| @@ -1 +1,9044 @@ | ||
| 1 | -(()=>{var e={65:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(8793),o=n(1323);function i(e){var t=(0,r.A)(e);return function(e){return(0,o.A)(t,e)}}},1323:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,n){if(e)throw t;return n}};function o(e,t){var n,o,i,a,l,s,c=[];for(n=0;n<e.length;n++){if(l=e[n],a=r[l]){for(o=a.length,i=Array(o);o--;)i[o]=c.pop();try{s=a.apply(null,i)}catch(e){return e}}else s=t.hasOwnProperty(l)?t[l]:+l;c.push(s)}return c[0]}},1364:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(65);function o(e){var t=(0,r.A)(e);return function(e){return+t({n:e})}}},8793:(e,t,n)=>{"use strict";var r,o,i,a;function l(e){for(var t,n,l,s,c=[],d=[];t=e.match(a);){for(n=t[0],(l=e.substr(0,t.index).trim())&&c.push(l);s=d.pop();){if(i[n]){if(i[n][0]===s){n=i[n][1]||n;break}}else if(o.indexOf(s)>=0||r[s]<r[n]){d.push(s);break}c.push(s)}i[n]||d.push(n),e=e.substr(t.index+n.length)}return(e=e.trim())&&c.push(e),c.concat(d.reverse())}n.d(t,{A:()=>l}),r={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1},o=["(","?"],i={")":["("],":":["?","?:"]},a=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/},7521:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(6956),o=n(7395);const i=function(e,t){return function(n,i,a){var l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,s=e[t];if((0,o.A)(n)&&(0,r.A)(i))if("function"==typeof a)if("number"==typeof l){var c={callback:a,priority:l,namespace:i};if(s[n]){var d,u=s[n].handlers;for(d=u.length;d>0&&!(l>=u[d-1].priority);d--);d===u.length?u[d]=c:u.splice(d,0,c),s.__current.forEach(function(e){e.name===n&&e.currentIndex>=d&&e.currentIndex++})}else s[n]={handlers:[c],runs:0};"hookAdded"!==n&&e.doAction("hookAdded",n,i,a,l)}else console.error("If specified, the hook priority must be a number.");else console.error("The hook callback must be a function.")}}},11:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(){var n,r,o=e[t];return null!==(n=null===(r=o.__current[o.__current.length-1])||void 0===r?void 0:r.name)&&void 0!==n?n:null}}},5375:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(7395);const o=function(e,t){return function(n){var o=e[t];if((0,r.A)(n))return o[n]&&o[n].runs?o[n].runs:0}}},3561:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(n){var r=e[t];return void 0===n?void 0!==r.__current[0]:!!r.__current[0]&&n===r.__current[0].name}}},8830:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(n,r){var o=e[t];return void 0!==r?n in o&&o[n].handlers.some(function(e){return e.namespace===r}):n in o}}},7765:(e,t,n)=>{"use strict";n.d(t,{A:()=>f});var r=n(3029),o=n(7521),i=n(4194),a=n(8830),l=n(6763),s=n(11),c=n(3561),d=n(5375),u=function e(){(0,r.A)(this,e),this.actions=Object.create(null),this.actions.__current=[],this.filters=Object.create(null),this.filters.__current=[],this.addAction=(0,o.A)(this,"actions"),this.addFilter=(0,o.A)(this,"filters"),this.removeAction=(0,i.A)(this,"actions"),this.removeFilter=(0,i.A)(this,"filters"),this.hasAction=(0,a.A)(this,"actions"),this.hasFilter=(0,a.A)(this,"filters"),this.removeAllActions=(0,i.A)(this,"actions",!0),this.removeAllFilters=(0,i.A)(this,"filters",!0),this.doAction=(0,l.A)(this,"actions"),this.applyFilters=(0,l.A)(this,"filters",!0),this.currentAction=(0,s.A)(this,"actions"),this.currentFilter=(0,s.A)(this,"filters"),this.doingAction=(0,c.A)(this,"actions"),this.doingFilter=(0,c.A)(this,"filters"),this.didAction=(0,d.A)(this,"actions"),this.didFilter=(0,d.A)(this,"filters")};const f=function(){return new u}},4194:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(6956),o=n(7395);const i=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(i,a){var l=e[t];if((0,o.A)(i)&&(n||(0,r.A)(a))){if(!l[i])return 0;var s=0;if(n)s=l[i].handlers.length,l[i]={runs:l[i].runs,handlers:[]};else for(var c=l[i].handlers,d=function(e){c[e].namespace===a&&(c.splice(e,1),s++,l.__current.forEach(function(t){t.name===i&&t.currentIndex>=e&&t.currentIndex--}))},u=c.length-1;u>=0;u--)d(u);return"hookRemoved"!==i&&e.doAction("hookRemoved",i,a),s}}}},6763:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(r){var o=e[t];o[r]||(o[r]={handlers:[],runs:0}),o[r].runs++;for(var i=o[r].handlers,a=arguments.length,l=new Array(a>1?a-1:0),s=1;s<a;s++)l[s-1]=arguments[s];if(!i||!i.length)return n?l[0]:void 0;var c={name:r,currentIndex:0};for(o.__current.push(c);c.currentIndex<i.length;){var d=i[c.currentIndex].callback.apply(null,l);n&&(l[0]=d),c.currentIndex++}return o.__current.pop(),n?l[0]:void 0}}},2133:(e,t,n)=>{"use strict";n.d(t,{se:()=>r});var r=(0,n(7765).A)();r.addAction,r.addFilter,r.removeAction,r.removeFilter,r.hasAction,r.hasFilter,r.removeAllActions,r.removeAllFilters,r.doAction,r.applyFilters,r.currentAction,r.currentFilter,r.doingAction,r.doingFilter,r.didAction,r.didFilter,r.actions,r.filters},7395:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e){return"string"!=typeof e||""===e?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}},6956:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e){return"string"!=typeof e||""===e?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}},772:(e,t,n)=>{"use strict";n.d(t,{h:()=>c});var r=n(4467),o=n(5397);function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach(function(t){(0,r.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var l={"":{plural_forms:function(e){return 1===e?0:1}}},s=/^i18n\.(n?gettext|has_translation)(_|$)/,c=function(e,t,n){var r=new o.A({}),i=new Set,c=function(){i.forEach(function(e){return e()})},d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";r.data[t]=a(a(a({},l),r.data[t]),e),r.data[t][""]=a(a({},l[""]),r.data[t][""])},u=function(e,t){d(e,t),c()},f=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default",t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;return r.data[e]||d(void 0,e),r.dcnpgettext(e,t,n,o,i)},m=function(){return arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default"},_=function(e,t,r){var o=f(r,t,e);return n?(o=n.applyFilters("i18n.gettext_with_context",o,e,t,r),n.applyFilters("i18n.gettext_with_context_"+m(r),o,e,t,r)):o};if(e&&u(e,t),n){var p=function(e){s.test(e)&&c()};n.addAction("hookAdded","core/i18n",p),n.addAction("hookRemoved","core/i18n",p)}return{getLocaleData:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";return r.data[e]},setLocaleData:u,resetLocaleData:function(e,t){r.data={},r.pluralForms={},u(e,t)},subscribe:function(e){return i.add(e),function(){return i.delete(e)}},__:function(e,t){var r=f(t,void 0,e);return n?(r=n.applyFilters("i18n.gettext",r,e,t),n.applyFilters("i18n.gettext_"+m(t),r,e,t)):r},_x:_,_n:function(e,t,r,o){var i=f(o,void 0,e,t,r);return n?(i=n.applyFilters("i18n.ngettext",i,e,t,r,o),n.applyFilters("i18n.ngettext_"+m(o),i,e,t,r,o)):i},_nx:function(e,t,r,o,i){var a=f(i,o,e,t,r);return n?(a=n.applyFilters("i18n.ngettext_with_context",a,e,t,r,o,i),n.applyFilters("i18n.ngettext_with_context_"+m(i),a,e,t,r,o,i)):a},isRTL:function(){return"rtl"===_("ltr","text direction")},hasTranslation:function(e,t,o){var i,a,l=t?t+""+e:e,s=!(null===(i=r.data)||void 0===i||null===(a=i[null!=o?o:"default"])||void 0===a||!a[l]);return n&&(s=n.applyFilters("i18n.has_translation",s,e,t,o),s=n.applyFilters("i18n.has_translation_"+m(o),s,e,t,o)),s}}}},5839:(e,t,n)=>{"use strict";n.d(t,{__:()=>a});var r=n(772),o=n(2133),i=(0,r.h)(void 0,void 0,o.se),a=(i.getLocaleData.bind(i),i.setLocaleData.bind(i),i.resetLocaleData.bind(i),i.subscribe.bind(i),i.__.bind(i));i._x.bind(i),i._n.bind(i),i._nx.bind(i),i.isRTL.bind(i),i.hasTranslation.bind(i)},9575:(e,t,n)=>{"use strict";n.d(t,{__:()=>r.__}),n(181),n(772);var r=n(5839)},181:(e,t,n)=>{"use strict";var r=n(8616),o=n.n(r);n(7604),o()(console.error)},1105:(e,t,n)=>{"use strict";n.r(t),n.d(t,{addonError:()=>f,afterAddonInstall:()=>u,extractErrorFromAddOnResponse:()=>d,toggleAddonState:()=>c});var r=n(9575);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,l=[],s=!0,c=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(r=i.call(n)).done)&&(l.push(r.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var a=frmDom,l=a.div,s=a.svg;function c(e,t){var n,r=null!==(n=window.ajaxurl)&&void 0!==n?n:frm_js.ajax_url;jQuery(".frm-addon-error").remove();var o=jQuery(e),i=o.attr("rel"),a=o.parent(),l=a.parent().find(".addon-status-label");o.addClass("frm_loading_button"),jQuery.ajax({url:r,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:t,nonce:frmGlobal.nonce,plugin:i},success:function(e){var n,r,i;"string"!=typeof(e=null!==(n=null===(r=e)||void 0===r?void 0:r.data)&&void 0!==n?n:e)&&"string"==typeof e.message&&(void 0!==e.saveAndReload&&(i=e.saveAndReload),e=e.message);var s=d(e);s?f(s,a,o):(u(e,o,l,a,i,t),wp.hooks.doAction("frm_update_addon_state",e))},error:function(){o.removeClass("frm_loading_button")}})}function d(e){return"string"!=typeof e&&!e.success&&(e.form&&jQuery(e.form).is("#message")?{message:jQuery(e.form).find("p").html()}:e)}function u(e,t,n,i,a){var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"frm_activate_addon",d=frm_admin_js,u=document.querySelectorAll(".frm-addon-status");u.forEach(function(t){t.textContent=e,t.style.display="block"}),t.css({opacity:"0"}),document.querySelectorAll(".frm-oneclick").forEach(function(e){e.style.display="none"}),function(){var e=document.getElementById("frm_upgrade_modal");if(e){e.classList.add("frm-success");var t=e.querySelector(".frm-upgrade-message");if(t){var n=t.querySelector("img");t.replaceChildren((0,r.__)("Great! Everything's ready to go!","formidable"),document.createElement("br"),(0,r.__)("You just need to refresh the builder so the new field becomes available.","formidable")),n&&t.append(n)}var o=document.querySelector(".frm-addon-status");o&&(o.textContent="");var i,a=e.querySelector(".frm-circled-icon");if(a)a.classList.add("frm-circled-icon-green"),null===(i=a.querySelector("svg"))||void 0===i||i.replaceWith(s({href:"#frm_checkmark_icon"}))}}();var f={frm_activate_addon:{class:"frm-addon-active",message:d.active},frm_deactivate_addon:{class:"frm-addon-installed",message:d.installed},frm_uninstall_addon:{class:"frm-addon-not-installed",message:d.not_installed}};f.frm_install_addon=f.frm_activate_addon;var _=o(n,1)[0];_&&(_.textContent=f[c].message);var p=o(i,1)[0].parentElement;p.classList.remove("frm-addon-not-installed","frm-addon-installed","frm-addon-active"),p.classList.add(f[c].class),o(t,1)[0].classList.remove("frm_loading_button"),document.querySelectorAll(".frm-admin-page-import, #frm-admin-smtp, #frm-welcome").length>0?window.location.reload():["settings","form_builder"].includes(a)&&u.forEach(function(e){var t=null!==e.closest("#frm_upgrade_modal");e.append(function(e,t){var n,o=[m(e)];return t&&o.push(((n=document.createElement("a")).setAttribute("href","#"),n.classList.add("button","button-secondary","frm-button-secondary","dismiss"),n.textContent=(0,r.__)("Not Now","formidable"),n)),l({className:"frm-save-and-reload-options",children:o})}(a,t))})}function f(e,t,n){e.form?(jQuery(".frm-inline-error").remove(),n.closest(".frm-card").html(e.form).css({padding:5}).find("#upgrade").attr("rel",n.attr("rel")).on("click",_)):(t.append('<div class="frm-addon-error frm_error_style"><p><strong>'.concat(e.message,"</strong></p></div>")),n.removeClass("frm_loading_button"),jQuery(".frm-addon-error").delay(4e3).fadeOut())}function m(e){var t=document.createElement("button");return t.classList.add("frm-save-and-reload","button","button-primary","frm-button-primary"),t.textContent=(0,r.__)("Save and Reload","formidable"),t.addEventListener("click",function(){var t;"form_builder"===e?((t=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&t.setAttribute("data-new-addon-installed",!0),t.click()):"settings"===e&&function(){var e=document.getElementById("form_settings_page");if(null!==e){var t=e.querySelector("form.frm_form_settings");null!==t&&(wp.hooks.doAction("frm_reset_fields_updated"),t.submit())}}()}),t}function _(e){e.preventDefault();var t=jQuery(this),n=t.parent().parent(),r=t.attr("rel");t.addClass("frm_loading_button"),jQuery.ajax({url:ajaxurl,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:"frm_install_addon",nonce:frmAdminJs.nonce,plugin:r,hostname:n.find("#hostname").val(),username:n.find("#username").val(),password:n.find("#password").val()},success:function(e){var r,o,i=d(e=null!==(r=null===(o=e)||void 0===o?void 0:o.data)&&void 0!==r?r:e);i?f(i,n,t):u(e,t,message,n)},error:function(){t.removeClass("frm_loading_button")}})}},4260:(e,t,n)=>{"use strict";n.r(t),n.d(t,{addOneClick:()=>i,initModal:()=>a,initUpgradeModal:()=>l});var r=n(9575),o=frmDom.svg;function i(e,t,n){var i;if("modal"===t)i=document.getElementById("frm_upgrade_modal");else{if("tab"!==t)return;i=document.getElementById(e.getAttribute("href").substr(1))}var a,l=i.querySelector(".frm-oneclick"),s=i.querySelector(".frm-upgrade-message"),c=i.querySelector(".frm-upgrade-link"),d=i.querySelector(".frm-oneclick-button"),u=i.querySelector(".frm-addon-status"),f=e.getAttribute("data-oneclick"),m=e.getAttribute("data-message"),_="block",p="block",g="none",y=i.querySelector(".frm-circled-icon");y&&(y.classList.remove("frm-circled-icon-green"),null===(a=y.querySelector("svg"))||void 0===a||a.replaceWith(o({href:"#frm_filled_lock_icon"})));var v=i.querySelector(".frm-learn-more");if(v&&(v.href=e.dataset.learnMore),null!==l&&null!==d&&void 0!==f&&f){null===m&&(p="none"),_="none",g="block",f=JSON.parse(f),d.className=d.className.replace(" frm-install-addon","").replace(" frm-activate-addon",""),d.className="".concat(d.className," ").concat(f.class),d.rel=f.url,l.textContent=(0,r.__)("This plugin is not activated. Would you like to activate it now?","formidable"),d.textContent=(0,r.__)("Activate","formidable");var h=e.querySelector("use");h&&(null==y||y.querySelector("svg").replaceWith(o({href:h.getAttribute("href")||h.getAttribute("xlink:href"),classList:["frm_svg32"]})))}m||(m=s.getAttribute("data-default")),void 0!==n&&(m=m.replace('<span class="frm_feature_label"></span>',n)),s.innerHTML=m,e.dataset.upsellImage&&s.append(frmDom.img({src:e.dataset.upsellImage,alt:e.dataset.upgrade})),c.href=function(e,t){var n=e.getAttribute("data-link");return null!=n&&""!==n||(n=t.getAttribute("data-default")),n}(e,c),u.style.display="none",l&&(l.style.display=g),d&&(d.style.display="block"===g?"inline-block":g),s.style.display=p,c.style.display="block"===_?"inline-block":_;var b=c.closest(".frm-upgrade-modal-actions");b&&(b.style.display="block"===_?"flex":_)}function a(e,t){var n=jQuery(e);if(!n.length)return!1;void 0===t&&(t="552px");var r={dialogClass:"frm-dialog",modal:!0,autoOpen:!1,closeOnEscape:!0,width:t,resizable:!1,draggable:!1,open:function(){var e,t;jQuery(".ui-dialog-titlebar").addClass("frm_hidden").removeClass("ui-helper-clearfix"),jQuery("#wpwrap").addClass("frm_overlay"),jQuery(".frm-dialog").removeClass("ui-widget ui-widget-content ui-corner-all"),n.removeClass("ui-dialog-content ui-widget-content"),e=n,t=function(){e.dialog("close")},jQuery(".ui-widget-overlay").on("click",t),e.on("click","a.dismiss",t)},close:function(){jQuery("#wpwrap").removeClass("frm_overlay"),jQuery(".spinner").css("visibility","hidden"),this.removeAttribute("data-option-type");var e=document.getElementById("bulk-option-type");e&&(e.value="")}};return n.dialog(r),n}function l(){var e=a("#frm_upgrade_modal");function t(t){var n,o,a;if((n=t.target).classList){var l=n.classList.contains("frm_show_expired_modal")||null!==n.querySelector(".frm_show_expired_modal")||n.closest(".frm_show_expired_modal");if("change"===t.type&&n.classList.contains("frm_select_with_upgrade")){var s=n.options[n.selectedIndex];s&&s.dataset.upgrade&&(n=s)}if(!n.dataset.upgrade){var c=n.closest("[data-upgrade]");if(!c){if(!(c=n.closest(".frm_field_box")))return;n.dataset.upgrade=""}n=c}if(l)wp.hooks.doAction("frm_show_expired_modal",n);else{var d=n.dataset.upgrade;if(d&&!n.classList.contains("frm_show_upgrade_tab")){t.preventDefault();var u=e.get(0);u.classList.remove("frm-success");var f=u.querySelector(".frm_lock_icon");f&&(f.style.display="block",f.classList.remove("frm_lock_open_icon"),f.querySelector("use").setAttribute("href","#frm_lock_icon"));var m="frm_upgrade_modal_image",_=document.getElementById(m);_&&_.remove(),n.dataset.image&&f&&(f.style.display="none",f.parentNode.insertBefore(frmDom.img({id:m,src:"".concat(frmGlobal.url,"/images/").concat(n.dataset.image)}),f));var p=u.querySelector(".license-level");p&&(p.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(n)),i(n,"modal",d);var g=u.querySelector(".frm_are_not_installed");g.style.display=n.dataset.image||n.dataset.oneclick?"none":"inline-block",g.textContent=g.dataset.default,u.querySelector(".frm-upgrade-modal-title-prefix").style.display=n.dataset.oneclick?"inline":"none",u.querySelector(".frm_feature_label").textContent=d,u.querySelector(".frm-upgrade-modal-title-suffix").style.display="none",u.querySelector("h2").style.display="block",e.dialog("open");var y=u.querySelector(".button-primary:not(.frm-oneclick-button)");o=y.getAttribute("href").replace(/(medium=)[a-z_-]+/gi,"$1".concat(n.getAttribute("data-medium"))),null===(a=n.getAttribute("data-content"))&&(a=""),o=o.replace(/(content=)[a-z_-]+/gi,"$1".concat(a)),y.setAttribute("href",o),n.classList.contains("frm_show_update")&&function(e){var t=e.querySelector(".frm-upgrade-modal-title-prefix");t&&(t.style.display="none");var n=e.querySelector(".frm_are_not_installed");n&&(n.textContent=(0,r.__)("require an update","formidable"),n.style.display="");var o=e.querySelector(".frm-oneclick");o&&(o.style.display="none");var i=e.querySelector(".frm-oneclick-button");i&&(i.textContent=(0,r.__)("Update Now","formidable"))}(u)}}}}!1!==e&&(document.addEventListener("click",t),frmDom.util.documentOn("change","select.frm_select_with_upgrade",t))}},8616:e=>{e.exports=function(e,t){var n,r,o=0;function i(){var i,a,l=n,s=arguments.length;e:for(;l;){if(l.args.length===arguments.length){for(a=0;a<s;a++)if(l.args[a]!==arguments[a]){l=l.next;continue e}return l!==n&&(l===r&&(r=l.prev),l.prev.next=l.next,l.next&&(l.next.prev=l.prev),l.next=n,l.prev=null,n.prev=l,n=l),l.val}l=l.next}for(i=new Array(s),a=0;a<s;a++)i[a]=arguments[a];return l={args:i,val:e.apply(null,i)},n?(n.prev=l,l.next=n):r=l,o===t.maxSize?(r=r.prev).next=null:o++,n=l,l.val}return t=t||{},i.clear=function(){n=null,r=null,o=0},i}},7604:(e,t,n)=>{var r;!function(){"use strict";var o={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function i(e){return function(e,t){var n,r,a,l,s,c,d,u,f,m=1,_=e.length,p="";for(r=0;r<_;r++)if("string"==typeof e[r])p+=e[r];else if("object"==typeof e[r]){if((l=e[r]).keys)for(n=t[m],a=0;a<l.keys.length;a++){if(null==n)throw new Error(i('[sprintf] Cannot access property "%s" of undefined value "%s"',l.keys[a],l.keys[a-1]));n=n[l.keys[a]]}else n=l.param_no?t[l.param_no]:t[m++];if(o.not_type.test(l.type)&&o.not_primitive.test(l.type)&&n instanceof Function&&(n=n()),o.numeric_arg.test(l.type)&&"number"!=typeof n&&isNaN(n))throw new TypeError(i("[sprintf] expecting number but found %T",n));switch(o.number.test(l.type)&&(u=n>=0),l.type){case"b":n=parseInt(n,10).toString(2);break;case"c":n=String.fromCharCode(parseInt(n,10));break;case"d":case"i":n=parseInt(n,10);break;case"j":n=JSON.stringify(n,null,l.width?parseInt(l.width):0);break;case"e":n=l.precision?parseFloat(n).toExponential(l.precision):parseFloat(n).toExponential();break;case"f":n=l.precision?parseFloat(n).toFixed(l.precision):parseFloat(n);break;case"g":n=l.precision?String(Number(n.toPrecision(l.precision))):parseFloat(n);break;case"o":n=(parseInt(n,10)>>>0).toString(8);break;case"s":n=String(n),n=l.precision?n.substring(0,l.precision):n;break;case"t":n=String(!!n),n=l.precision?n.substring(0,l.precision):n;break;case"T":n=Object.prototype.toString.call(n).slice(8,-1).toLowerCase(),n=l.precision?n.substring(0,l.precision):n;break;case"u":n=parseInt(n,10)>>>0;break;case"v":n=n.valueOf(),n=l.precision?n.substring(0,l.precision):n;break;case"x":n=(parseInt(n,10)>>>0).toString(16);break;case"X":n=(parseInt(n,10)>>>0).toString(16).toUpperCase()}o.json.test(l.type)?p+=n:(!o.number.test(l.type)||u&&!l.sign?f="":(f=u?"+":"-",n=n.toString().replace(o.sign,"")),c=l.pad_char?"0"===l.pad_char?"0":l.pad_char.charAt(1):" ",d=l.width-(f+n).length,s=l.width&&d>0?c.repeat(d):"",p+=l.align?f+n+s:"0"===c?f+s+n:s+f+n)}return p}(function(e){if(l[e])return l[e];for(var t,n=e,r=[],i=0;n;){if(null!==(t=o.text.exec(n)))r.push(t[0]);else if(null!==(t=o.modulo.exec(n)))r.push("%");else{if(null===(t=o.placeholder.exec(n)))throw new SyntaxError("[sprintf] unexpected placeholder");if(t[2]){i|=1;var a=[],s=t[2],c=[];if(null===(c=o.key.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(a.push(c[1]);""!==(s=s.substring(c[0].length));)if(null!==(c=o.key_access.exec(s)))a.push(c[1]);else{if(null===(c=o.index_access.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");a.push(c[1])}t[2]=a}else i|=2;if(3===i)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");r.push({placeholder:t[0],param_no:t[1],keys:t[2],sign:t[3],pad_char:t[4],align:t[5],width:t[6],precision:t[7],type:t[8]})}n=n.substring(t[0].length)}return l[e]=r}(e),arguments)}function a(e,t){return i.apply(null,[e].concat(t||[]))}var l=Object.create(null);"undefined"!=typeof window&&(window.sprintf=i,window.vsprintf=a,void 0===(r=function(){return{sprintf:i,vsprintf:a}}.call(t,n,t,e))||(e.exports=r))}()},5397:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(1364),o={contextDelimiter:"",onMissingKey:null};function i(e,t){var n;for(n in this.data=e,this.pluralForms={},this.options={},o)this.options[n]=void 0!==t&&n in t?t[n]:o[n]}i.prototype.getPluralForm=function(e,t){var n,o,i,a=this.pluralForms[e];return a||("function"!=typeof(i=(n=this.data[e][""])["Plural-Forms"]||n["plural-forms"]||n.plural_forms)&&(o=function(e){var t,n,r;for(t=e.split(";"),n=0;n<t.length;n++)if(0===(r=t[n].trim()).indexOf("plural="))return r.substr(7)}(n["Plural-Forms"]||n["plural-forms"]||n.plural_forms),i=(0,r.A)(o)),a=this.pluralForms[e]=i),a(t)},i.prototype.dcnpgettext=function(e,t,n,r,o){var i,a,l;return i=void 0===o?0:this.getPluralForm(e,o),a=n,t&&(a=t+this.options.contextDelimiter+n),(l=this.data[e][a])&&l[i]?l[i]:(this.options.onMissingKey&&this.options.onMissingKey(n,e),0===i?n:r)}},3029:(e,t,n)=>{"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}n.d(t,{A:()=>r})},4467:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(9922);function o(e,t,n){return(t=(0,r.A)(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},2327:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(2284);function o(e,t){if("object"!=(0,r.A)(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=(0,r.A)(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}},9922:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(2284),o=n(2327);function i(e){var t=(0,o.A)(e,"string");return"symbol"==(0,r.A)(t)?t:t+""}},2284:(e,t,n)=>{"use strict";function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}n.d(t,{A:()=>r})}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}function r(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||o(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},window.FrmFormsConnect=window.FrmFormsConnect||function(e,t,n){var r={messageBox:null,reset:null,setElements:function(){r.messageBox=e.querySelector(".frm_pro_license_msg"),r.reset=e.getElementById("frm_reconnect_link")}},o={init:function(){r.setElements(),n(e.getElementById("frm_deauthorize_link")).on("click",o.deauthorize),n(".frm_authorize_link").on("click",o.authorize),n(".frm-dashboard-license-options").on("click","#frm_deauthorize_link",o.deauthorize),n(".frm-dashboard-license-options").on("click","#frm_reconnect_link",o.reauthorize),null!==r.reset&&n(r.reset).on("click",o.reauthorize)},authorize:function(){var t=this,r=this.getAttribute("data-plugin"),i=e.getElementById("edd_".concat(r,"_license_key")),a=i.value,l=e.getElementById("proplug-wpmu");this.classList.add("frm_loading_button"),l=null===l?0:l.checked?1:0,n.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_activate",license:a,plugin:r,wpmu:l,nonce:frmGlobal.nonce},success:function(e){o.afterAuthorize(e,i),t.classList.remove("frm_loading_button")}})},afterAuthorize:function(e,t){!0===e.success&&(t.value="•••••••••••••••••••"),wp.hooks.doAction("frm_after_authorize",e),o.showMessage(e)},showProgress:function(e){null===r.messageBox&&r.setElements();var t=r.messageBox;null!==t&&(!0===e.success?(t.classList.remove("frm_error_style"),t.classList.add("frm_message","frm_updated_message")):(t.classList.add("frm_error_style"),t.classList.remove("frm_message","frm_updated_message")),t.classList.remove("frm_hidden"),t.innerHTML=e.message)},showMessage:function(n){null===r.messageBox&&r.setElements();var i=r.messageBox;!0===n.success&&(o.showAuthorized(!0),o.showInlineSuccess(),wp.hooks.doAction("frmAdmin.afterLicenseAuthorizeSuccess",{msg:n})),o.showProgress(n),""!==n.message&&(setTimeout(function(){i.innerHTML="",i.classList.add("frm_hidden"),i.classList.remove("frm_error_style","frm_message","frm_updated_message")},1e4),e.querySelector(".frm-admin-page-dashboard")&&setTimeout(function(){t.location.reload()},1e3))},showAuthorized:function(t){var n=t?"unauthorized":"authorized",r=t?"authorized":"unauthorized",o=e.querySelectorAll(".frm_".concat(n,"_box"));o.length&&o.forEach(function(e){e.className=e.className.replace("frm_".concat(n,"_box"),"frm_".concat(r,"_box"))})},showInlineSuccess:function(){var t=e.querySelectorAll(".frm-confirm-msg [data-success]");t.length&&t.forEach(function(e){e.innerHTML=frmAdminBuild.purifyHtml(e.getAttribute("data-success"))})},reauthorize:function(){return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>',n.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_reset_cache",plugin:"formidable_pro",nonce:frmGlobal.nonce},success:function(e){r.reset.textContent=e.message,"1"===r.reset.getAttribute("data-refresh")&&t.location.reload()}}),!1},deauthorize:function(){if(!confirm(frmGlobal.deauthorize))return!1;var t=this.getAttribute("data-plugin"),r=e.getElementById("edd_".concat(t,"_license_key")),i=r.value,a=this;return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;"></span>',n.ajax({type:"POST",url:ajaxurl,data:{action:"frm_addon_deactivate",license:i,plugin:t,nonce:frmGlobal.nonce},success:function(){o.showAuthorized(!1),r.value="",a.replaceWith("Disconnected"),wp.hooks.doAction("frmAdmin.afterLicenseDeauthorizeSuccess",{})}}),!1}};return o}(document,window,jQuery),window.frmAdminBuildJS=function(){var e,t,i=frm_admin_js,l=frmDom,s=l.tag,c=l.div,d=l.span,u=l.a,f=l.svg,m=l.img,_=frmDom.util.onClickPreventDefault,p=frmDom.ajax.doJsonPost;i.contextualShortcodes=(t=null===(e=document.getElementById("frm_adv_info"))||void 0===e?void 0:e.dataset.contextualShortcodes)?((t=JSON.parse(t)).addressSelector="[id^=email_to], [id^=from_], [id^=cc], [id^=bcc]",t.bodySelector="[id^=email_message_]",t):[];var g,y,v,h={save:f({href:"#frm_save_icon"}),drag:f({href:"#frm_drag_icon",classList:["frm_drag_icon","frm-drag"]})},b=jQuery(document.getElementById("frm-show-fields")),j=document.getElementById("new_fields"),w=document.getElementById("form_id"),Q=!1,x=0,E=0,k=0,A={},S=0,L=wp.i18n,I=L.__,B=L.sprintf,q={dragging:!1};null!==w&&(E=w.value);var C,N=new URL(window.location.href),T=N.searchParams,O=document.getElementById("frm_builder_page");function F(e){e.stopPropagation(),e.preventDefault(),D(this)}function D(e){var t=e.getAttribute("data-frmverify"),n=e.getAttribute("data-loaded-from");return null===t||"frm-confirmed-click"===e.id||("entries-list"===n?wp.hooks.applyFilters("frm_on_multiple_entries_delete",{link:e,initModal:Bi}):function(e){var t=Bi("#frm_confirm_modal","400px"),n=document.getElementById("frm-confirmed-click");if(!1===t)return!1;n&&(n.style.display="block");var r=e.getAttribute("data-frmverify"),o=r?e.getAttribute("data-frmverify-btn"):"",i=jQuery(".frm-confirm-msg");i.empty(),r&&(i.append(document.createTextNode(r)),o&&(null==n||n.classList.add(o)));var a=e.dataset;if(n){for(var l in n.dataset)n.removeAttribute("data-".concat(l));for(var s in a)"frmverify"!==s&&n.setAttribute("data-".concat(s),a[s])}return wp.hooks.doAction("frmAdmin.beforeOpenConfirmModal",{$info:t,link:e}),t.dialog("open"),null==n||n.setAttribute("href",e.getAttribute("href")||e.getAttribute("data-href")),!1}(e))}function M(e){var t=Bi("#frm_info_modal","400px");return!1===t||(jQuery(".frm-info-msg").html(e),t.dialog("open")),!1}function P(e){var t=this.getAttribute("data-frmtoggle"),n=this.getAttribute("data-toggletext"),r=jQuery(t);return e.preventDefault(),r.toggle(),null!==n&&""!==n&&(this.setAttribute("data-toggletext",this.innerHTML),this.textContent=n),!1}function H(e){var t=this.getAttribute("data-frmhide"),n=this.getAttribute("data-frmshow"),r=this.getAttribute("data-frmuncheck"),o=r?r.split(","):[];"INPUT"!==this.nodeName||"checkbox"!==this.type||this.checked||(null!==t?(n=t,t=null):null!==n&&(t=n,n=null)),e.preventDefault();var i=this.getAttribute("data-toggleclass")||"frm_hidden";null!==t&&jQuery(t).addClass(i),null!==n&&jQuery(n).removeClass(i);var a=this.parentNode.querySelectorAll("a.current");if(null!==a){for(var l=0;l<a.length;l++)a[l].classList.remove("current");this.classList.add("current")}return o.length&&o.forEach(function(e){var t=document.querySelector(e);t&&(t.checked=!1)}),!1}function z(){document.querySelectorAll(".tooltip").forEach(function(e){e.remove()})}function R(){var e,t,n;if(!parseInt(this.getAttribute("data-skip-frm-js"))&&!1!==D(this)){var r=jQuery(this),o=r.attr("data-removeid");void 0===(e=r.attr("data-showlast"))&&(e=""),void 0===(t=r.attr("data-hidelast"))&&(t=""),n=r.attr("data-removemore"),""!==e?r.closest(".frm_add_remove").find(".frm_remove_tag:visible").length>1&&(e="",t=""):0===o.indexOf("frm_postmeta_")&&(jQuery("#frm_postmeta_rows .frm_postmeta_row").length<2&&(e=".frm_add_postmeta_row.button"),jQuery(".frm_toggle_cf_opts").length&&jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().length&&(""!==e&&(e+=","),e+="#".concat(jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().attr("id")," .frm_toggle_cf_opts")));var i=document.getElementById(o),a=jQuery(i);return a.fadeOut(300,function(){var n;a.remove(),Po(),""!==t&&jQuery(t).hide(),""!==e&&jQuery("".concat(e," a,").concat(e)).removeClass("frm_hidden").fadeIn("slow"),this.closest(".frm_form_action_settings")&&function(e){so(e);var t={type:e};wp.hooks.doAction("frm_after_action_removed",t)}(this.closest(".frm_form_action_settings").querySelector(".frm_action_name").value),null===(n=document.querySelector(".tooltip"))||void 0===n||n.remove()}),void 0!==n&&(n=jQuery(n)).fadeOut(400,function(){n.remove()}),""!==e&&jQuery(this).closest(".frm_logic_rows").fadeOut("slow"),wp.hooks.doAction("frm_admin_tag_removed",o,i),!1}}function G(e,t){void 0===t&&(t=this),Ze(t,!1);var n=jQuery(t).closest(".frm_form_action_settings"),r=e.target;if(n.length&&void 0!==r){var o=r.parentElement.className;if("string"==typeof o&&(o.includes("frm_email_icons")||o.includes("frm_toggle")))return void e.stopPropagation()}var i=n.children(".widget-inside");if(n.length&&i.find("p, div, table").length<1){var a=n.find('input[name$="[ID]"]').val(),l=n.find('input[name$="[post_excerpt]"]').val();l&&(i.html('<span class="frm-wait frm_spinner"></span>'),n.find(".spinner").fadeIn("slow"),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_form_action_fill",action_id:a,action_type:l,nonce:frmGlobal.nonce},success:function(e){i.html(e),ci(),Xr("#".concat(n.attr("id"))),yi(i),jQuery(t).trigger("frm-action-loaded"),wp.hooks.doAction("frm_filled_form_action",i)}}))}jQuery(t).closest(".frm_field_box").siblings().find(".widget-inside").slideUp("fast"),void 0!==t.className&&t.className.includes("widget-action")||jQuery(t).closest(".start_divider").length<1||((i=jQuery(t).closest("div.widget").children(".widget-inside")).is(":hidden")?i.slideDown("fast"):i.slideUp("fast"))}function U(){var e=this.getAttribute("href");if(void 0===e)return!1;var t=e.replace("#","."),n=jQuery(this);n.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),n.closest("div").children(".tabs-panel").not(e).not(t).hide();var r=document.getElementById(e.replace("#",""));return r&&(r.style.display="block"),"frm_insert_fields_tab"!==this.id||this.closest("#frm_adv_info")||$e(),!1}function W(e,t){var n=(e=jQuery(e)).attr("href");if(void 0!==n){var r,o,i=n.replace("#",".");if(e.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),e.closest("div").find(".tabs-panel").length)e.closest("div").children(".tabs-panel").not(n).not(i).hide();else if(null!==document.getElementById("form_global_settings")){var a=e.data("frmajax");e.closest(".frm_wrap").find(".tabs-panel, .hide_with_tabs").hide(),void 0!==a&&"1"==a&&(r=n.replace("#",""),(o=jQuery(".frm_".concat(r,"_ajax"))).length&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_settings_tab",tab:r.replace("_settings",""),nonce:frmGlobal.nonce},success:function(e){o.replaceWith(e)}}))}else jQuery("#frm-categorydiv .tabs-panel, .hide_with_tabs").hide();jQuery(n).show(),jQuery(i).show(),$o(),"auto"!==t&&(jQuery(".frm_updated_message").hide(),jQuery(".frm_warning_style").hide()),jQuery(e).closest("#frm_adv_info").length||(jQuery(".frm_form_settings").length?jQuery(".frm_form_settings").attr("action","?page=formidable&frm_action=settings&id=".concat(jQuery('.frm_form_settings input[name="id"]').val(),"&t=").concat(n.replace("#",""))):jQuery(".frm_settings_form").attr("action","?page=formidable-settings&t=".concat(n.replace("#",""))))}}function V(e){var t,n;document.querySelectorAll(e).forEach(function(e){$(e),Array.from(e.children).forEach(function(e){return X(e,".frm-move")});var t=jQuery(e).children('[data-type="divider"]').children(".divider_section_only");t.length&&$(t)}),t=jQuery("#frm_builder_page"),n={items:".frm_sortable_field_opts li",axis:"y",opacity:.65,forcePlaceholderSize:!1,handle:".frm-drag",helper:function(e,t){return Q=t.clone().insertAfter(t),t.clone()},stop:function(e,t){Q&&Q.remove(),ir(t.item.attr("id").replace("frm_delete_field_","").replace("-".concat(t.item.data("optkey"),"_container"),"")),Po()}},jQuery(t).sortable(n)}function $(e){jQuery(e).droppable({accept:".frmbutton, li.frm_field_box",deactivate:ne,over:K,out:J,tolerance:"pointer"})}function K(e,t){var n=function(e){return e.classList.contains("divider_section_only")&&(e=jQuery(e).nextAll(".start_divider.frm_sorting").get(0)),e}(e.target);if(!je(t.draggable[0],n,e))return n.classList.remove("frm-over-droppable"),void jQuery(n).parents("ul.frm_sorting").addClass("frm-over-droppable");document.querySelectorAll(".frm-over-droppable").forEach(function(e){return e.classList.remove("frm-over-droppable")}),n.classList.add("frm-over-droppable"),jQuery(n).parents("ul.frm_sorting").addClass("frm-over-droppable")}function J(e){e.target.classList.remove("frm-over-droppable")}function X(e,t){var n={helper:Y,revert:"invalid",delay:10,start:Z,stop:ee,drag:te,cursor:"grabbing",refreshPositions:!0,cursorAt:{top:0,left:90}};"string"==typeof t&&(n.handle=t),jQuery(e).draggable(n)}function Y(e){var t,n=e.delegateTarget;if(Qe(n)){var r=document.getElementById("frm-insert-fields").querySelector(".frm_ttext").cloneNode(!0);return r.querySelector("use").setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_field_group_layout_icon"),r.querySelector("span").textContent=I("Field Group","formidable"),r.classList.add("frm_field_box"),r.classList.add("ui-sortable-helper"),r}if(n.classList.contains("frmbutton"))return(t=n.cloneNode(!0)).classList.add("ui-sortable-helper"),n.classList.add("frm-new-field"),t;if(n.hasAttribute("data-ftype")){var o=n.getAttribute("data-ftype");if(t=document.getElementById("frm-insert-fields").querySelector(".frm_t".concat(o)))return(t=t.cloneNode(!0)).classList.add("form-field"),t.classList.add("ui-sortable-helper"),t.cloneNode(!0)}return c({className:"frmbutton"})}function Z(e,t){if(e.target.classList.contains("frm_at_limit"))return Se(),!1;q.dragging=!0;var n,r=y;r.classList.add("frm-dragging-field"),document.body.classList.add("frm-dragging"),t.helper.addClass("frm-sortable-helper"),t.helper.initialOffset=r.scrollTop,e.target.classList.add("frm-drag-fade"),vn(),(n=document.querySelectorAll("ul.start_divider")).length&&n.forEach(function(e){[].slice.call(e.children).forEach(function(e){(0===e.children.length||1===e.children.length&&"ul"===e.firstElementChild.nodeName.toLowerCase()&&0===e.firstElementChild.children.length)&&e.remove()})}),Fe(),Ne(),z()}function ee(){y.classList.remove("frm-dragging-field"),document.body.classList.remove("frm-dragging");var e=document.querySelector(".frm-drag-fade");e&&e.classList.remove("frm-drag-fade")}function te(e,t){!function(e){v.scrollTop(function(t,n){var r=e.clientY,o=y.offsetHeight,i=e.clientY-y.offsetTop,a=i-o/2;return i>o-50&&r>5?n+.1*a:i<70&&r<130?n-Math.abs(.1*a):n})}(e);var n=e.target,r=function(){for(var e=document.getElementById("frm-show-fields");e.querySelector(".frm-over-droppable");)e=e.querySelector(".frm-over-droppable");return"frm-show-fields"!==e.id||e.classList.contains("frm-over-droppable")||(e=!1),e}(),o=document.getElementById("frm_drag_placeholder");if(je(n,r,e)){o||(o=s("li",{id:"frm_drag_placeholder",className:"sortable-placeholder"}));var i,a=t.helper.get(0);if((a.classList.contains("form-field")||a.classList.contains("frm_field_box"))&&(a.style.transform="translateY(".concat((i=t.helper,y.scrollTop-i.initialOffset),"px)")),"frm-show-fields"===r.id||r.classList.contains("start_divider"))return o.style.left=0,void function(e){var t,n=e.y,r=e.placeholder,o=jQuery(e.droppable),i=o.children().not(".edit_field_type_end_divider");if(0===i.length)o.prepend(r),t=0;else{var a=re(o,n);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().top+l.outerHeight(),o.append(r);var s=o.children(".edit_field_type_end_divider");s.length&&o.append(s)}else t=jQuery(i.get(a)).offset().top,jQuery(i.get(a)).before(r)}t-=o.offset().top,r.style.top="".concat(t,"px")}({droppable:r,y:e.clientY,placeholder:o});o.style.top="",function(e){var t,n=e.x,r=e.placeholder,o=jQuery(e.droppable),i=ie(o);if(i.length){var a=function(e,t){var n,r,o,i,a=ie(e);for(i=0,n=a.length-1;n>=0;--n)if(r=a.get(n),t>(o=jQuery(r).offset().left)){i=n,t>o+jQuery(r).outerWidth()/2&&(i=n+1);break}return i}(o,n);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().left+l.outerWidth(),o.append(r)}else t=jQuery(i.get(a)).offset().left,jQuery(i.get(a)).before(r),t-=0===a?4:8;t-=o.offset().left,r.style.left="".concat(t,"px")}}({droppable:r,x:e.clientX,placeholder:o})}else o&&o.remove()}function ne(e,t){if(q.dragging){q.dragging=!1;var n=t.draggable[0],r=document.getElementById("frm_drag_placeholder");if(!r)return t.helper.remove(),void g();!function(e){if(e.previousElementSibling&&e.previousElementSibling.classList.contains("frm-is-collapsed")){var t=jQuery(e).prevUntil('[data-type="break"]');if(t.length){var n=t.find(".frm-collapse-page").get(0);n&&n.click()}}}(r);var o=t.helper.parent(),i=t.helper.get(0).closest("ul.start_divider"),a=r.closest("ul.start_divider");n.classList.contains("frm-new-field")?function(e){if(pe(e))wp.hooks.doAction("frm_stopped_inserting_by_dragging",e);else{var t=document.getElementById("frm_drag_placeholder"),n="".concat(e.replace("|","-"),"_").concat(be()),r=s("li",{id:n,className:"frm-wait frmbutton_loadingnow"}),o=jQuery(r),i=de(jQuery(t)),a=ue(i),l=fe(i);t.parentNode.insertBefore(r,t),t.remove(),ae(o);var c=0;"summary"===e&&(c=jQuery(".frmbutton_loadingnow#".concat(n)).prevAll('li[data-type="break"]').length?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:_e(e,l,a,c),success:function(t){ge(t,o);var n=ye(t);n&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:n,fieldType:e,form_id:a})},error:he})}}(n.id):(function(e,t){t.parentNode.insertBefore(e,t)}(n,r),function(e){if("UL"===e.nodeName&&!e.classList.contains("start_divider")&&"frm-show-fields"!==e.id){var t=e.closest("li");t&&!t.classList.contains("ui-draggable")&&X(t,".frm-move")}}(r.parentElement));var l=i?parseInt(i.closest(".edit_field_type_divider").getAttribute("data-fid")):0,c=a?parseInt(a.closest(".edit_field_type_divider").getAttribute("data-fid")):0;r.remove(),t.helper.remove();var d=o.length?ie(o):[];!function(e,t){var n;e.length&&(t.length?ae(t.first()):(n=e.get(0).closest("li.frm_field_box"))&&!n.classList.contains("edit_field_type_divider")&&n.remove())}(o,d),function(e,t){0===t.length&&1===ie(jQuery(e.parentNode)).length||ae(jQuery(e))}(n,d),l!==c&&me(jQuery(n),i),g()}}function re(e,t){var n,r,o,i,a=e.children().not(".edit_field_type_end_divider"),l=a.length;if(!document.querySelector(".frm-has-fields .frm_no_fields"))return 0;for(i=0,n=l-1;n>=0;--n)if(r=a.get(n),t>(o=jQuery(r).offset().top)){i=n,t>o+jQuery(r).outerHeight()/2&&(i=n+1);break}return i}function oe(){document.querySelectorAll("ul#frm-show-fields, ul.start_divider").forEach(function(e){e.childNodes.forEach(function(e){void 0!==e.classList&&(e.classList.contains("edit_field_type_end_divider")||void 0!==e.classList&&e.classList.contains("form-field")&&Ue(e))})}),kr(),document.querySelectorAll(".edit_field_type_end_divider").forEach(function(e){return e.parentNode.append(e)}),document.querySelectorAll("li.form_field_box:not(.form-field)").forEach(function(e){return!e.children.length&&e.remove()}),Er();var e=new Event("frm_sync_after_drag_and_drop",{bubbles:!1});document.dispatchEvent(e)}function ie(e){var t=jQuery(),n=e.get(0);return n.children?(Array.from(n.children).forEach(function(e){if("none"!==e.style.display){var n=e.classList;!n.contains("form-field")||n.contains("edit_field_type_end_divider")||n.contains("frm-sortable-helper")||(t=t.add(e))}}),t):t}function ae(e,t){var n;void 0===t&&(t="even");var r=e.parent().children("li.form-field, li.frmbutton_loadingnow").not(".edit_field_type_end_divider"),o=r.length,i=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"];"even"===t&&5!==o?r.each(ce(i,$t(o))):"clear"===t?r.each(ce(i,"")):(n=["left","right","middle","even"].includes(t)?function(e){return Vt(o,t,e)}:function(e){return sn(t[e])},r.each(ce(i,n))),le(e.parent(),r.length)}function le(e,t){if(void 0!==e.offset()){var n=t>=2,r=document.getElementById("frm_field_group_controls");if(null===r){if(!n)return;(r=c()).id="frm_field_group_controls",r.setAttribute("role","group"),r.setAttribute("tabindex",0),function(e){var t=document.createElement("span");t.innerHTML='<svg class="frmsvg"><use href="#frm_field_group_layout_icon"></use></svg>';var n=I("Set Row Layout","formidable");se(t,n),zt(t,n);var r=document.createElement("span");r.innerHTML='<svg class="frmsvg"><use href="#frm_thick_move_icon"></use></svg>',r.classList.add("frm-move");var o=I("Move Field Group","formidable");se(r,o),zt(r,o),e.innerHTML="",e.append(t),e.append(r),e.append(function(){var e=d({className:"dropdown"}),t=u({className:"frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle",children:[d({child:f({href:"#frm_thick_more_vert_icon"})}),d({className:"screen-reader-text",text:I("Toggle More Options Dropdown","formidable")})]});frmDom.setAttributes(t,{title:I("More Options","formidable"),"data-bs-toggle":"dropdown","data-bs-container":"body","data-bs-display":"static"}),zt(t,I("More Options","formidable")),e.append(t);var n=c({className:"frm-dropdown-menu dropdown-menu dropdown-menu-right"});return n.setAttribute("role","menu"),e.append(n),e}())}(r),O.append(r)}e.append(r),r.style.display=n?"block":"none"}}function se(e,t){e.setAttribute("data-bs-toggle","tooltip"),e.setAttribute("data-bs-container","body"),e.setAttribute("title",t),e.addEventListener("mouseover",function(){null===e.getAttribute("data-original-title")&&jQuery(e).tooltip()})}function ce(e,t){return function(n){for(var r="function"==typeof t?t(n):t,o=e.length,i=!1,a=0;a<o;++a){var l=e[a];if(this.classList.contains(l)){i=l;break}}var s=this.dataset.fid;if(void 0!==s){oo(document.getElementById("frm-single-settings-".concat(s)));var c=document.getElementById("frm_classes_".concat(s));null!==c&&(!1===i?""!==r&&(c.value=c.value.concat(" ".concat(r))):(this.classList.remove(i),c.value=c.value.replace(i,r)),this.classList.contains("frm_first")&&(this.classList.remove("frm_first"),c.value=c.value.replace("frm_first","").trim()),0===n&&(this.classList.add("frm_first"),c.value=c.value.concat(" frm_first")),jQuery(c).trigger("change"))}else this.classList.add(r)}}function de(e){var t="";return void 0===e||e.hasClass("edit_field_type_divider")||(t=e.closest(".edit_field_type_divider")),t}function ue(e){var t="";if(void 0!==e[0]){var n=e.children(".start_divider");if(n.children(".edit_field_type_end_divider").appendTo(n),void 0!==e.attr("data-formid")){var r=e.attr("data-fid");t=jQuery('input[name="field_options[form_select_'.concat(r,']"]')).val()}}return void 0!==t&&""!==t||(t=E),t}function fe(e){var t=0;return void 0!==e[0]&&(t=e.attr("id").replace("frm_field_id_","")),t}function me(e,t){if(e.hasClass("form-field")){var n=e.attr("id").replace("frm_field_id_",""),r=de(e),o=ue(r),i=fe(r),a=t?ue(jQuery(t.parentNode)):0;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_update_field_after_move",form_id:o,field:n,section_id:i,previous_form_id:a,nonce:frmGlobal.nonce},success:function(){kr(),function(e,t){document.getElementById("frm_in_section_".concat(e)).value=t}(n,i)}})}else ie(jQuery(e.get(0).firstChild)).each(function(){me(jQuery(this),t)})}function _e(e,t,n,r){var o={action:"frm_insert_field",form_id:n,field_type:e,section_id:t,nonce:frmGlobal.nonce,has_break:r};return t>0&&document.getElementById("form_id").value!==n||(o.last_row_field_ids=function(){var e=document.querySelector(".edit_field_type_submit");if(!e)return[];for(var t=e.parentNode.children,n=[],r=0;r<t.length;r++)n.push(t[r].dataset.fid);return n}()),o}function pe(e){return wp.hooks.applyFilters("frm_should_stop_inserting_field",!1,e)}function ge(e,t){var n;document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var r=t.siblings("li.form-field").not(".edit_field_type_end_divider");r.length?(n=ve(e),t.get(0).parentNode.parentNode.classList.contains("ui-draggable")||X(t.get(0).parentNode.parentNode,".frm-move")):n=Ge(e),t.replaceWith(n),Er(),We(e,!1),r.length&&ae(r.first()),kr(),r.length?X(n.get(0),".frm-move"):($(n.get(0).querySelector("ul.frm_sorting")),X(n.get(0).querySelector("li.form-field"),".frm-move"))}function ye(e){var t=e.match(/data-fid="(\d+)"/);return t?parseInt(t[1]):0}function ve(e){var t=c();return t.innerHTML=e,jQuery(t.firstChild)}function he(e,t,n){!function(e,t){(function(e){return 0===e.status||0===e.readyState})(t)||M("".concat(e,". Please try again."))}(n,e)}function be(){return++k}function je(e,t,n){if(!1===t)return!1;if(t.closest(".frm-sortable-helper"))return!1;var r=e.classList.contains("edit_field_type_submit"),o=!e.classList.contains("form_field")&&!!e.querySelector(".edit_field_type_submit");if("frm-show-fields"===t.id){var i=re(jQuery(t),n.clientY);return r||o?i>t.childElementCount-1:i<=jQuery(t.querySelector(".edit_field_type_submit").closest("#frm-show-fields > li")).index()}if(r)return!(t.classList.contains("start_divider")||!we(t.parentElement)&&(!we(t.parentElement.nextElementSibling)||e.parentElement.querySelector("li.frm_field_box:not(.edit_field_type_submit)")));var a=t.classList.contains("start_divider")&&null!==t.closest(".repeat_section"),l=null!==t.closest(".repeat_section");if(a||l){if(e.classList.contains("edit_field_type_gdpr")||"gdpr"===e.id)return!1;if(wp.hooks.applyFilters("frm_deny_drop_in_repeater",!1,e))return!1}if(!a){if(!function(e,t){if(e.length<12)return!0;if(e.length>12)return!1;var n=t.attr("data-fid");return 1===jQuery(e).filter('[data-fid="'.concat(n,'"]')).length}(ie(jQuery(t)),jQuery(e)))return!1;if("divider"===e.id&&t.closest(".start_divider"))return!1}return e.classList.contains("frm-new-field")?function(e,t){var n=e.classList,r=n.contains("frm_tbreak"),o=n.contains("frm_thidden"),i=n.contains("frm_tdivider"),a=n.contains("frm_tform"),l=n.contains("frm_tuser_id");return"frm-show-fields"===t.id||t.classList.contains("start_divider")?!(r||o||i||a)||(!(t.classList.contains("start_divider")||null!==t.closest(".start_divider"))||!a&&!i):!(xe(t)||o||r||l)}(e,t):function(e,t){if(Qe(e))return function(e,t){return!(!t.classList.contains("start_divider")||null!==e.querySelector(".start_divider"))}(e,t);if(e.classList.contains("edit_field_type_break"))return!1;if(t.classList.contains("start_divider"))return function(e){return!e.classList.contains("edit_field_type_form")&&!e.querySelector(".edit_field_type_form")&&!(e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"))}(e);var n=e.classList.contains("edit_field_type_hidden"),r=e.classList.contains("edit_field_type_user_id");return!n&&!r&&function(e,t){if(xe(t))return!1;if(jQuery(e).children("ul.frm_sorting").not(".start_divider").length>0)return!1;var n=e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"),r=e.classList.contains("edit_field_type_form");return null===t.closest(".start_divider")||!n&&!r}(e,t)}(e,t)}function we(e){return e&&e.matches("#frm-show-fields > li:last-child")}function Qe(e){return e.classList.contains("frm_field_box")&&!e.classList.contains("form-field")}function xe(e){return null!==e.querySelector(".edit_field_type_break, .edit_field_type_hidden, .edit_field_type_user_id")}function Ee(e){var t=document.getElementById(e),n=jQuery(t),r=[],o=function(e){var t=e.querySelector(".frm_hidden_fdata");e.classList.add("frm_load_now"),null!==t&&r.push(t.innerHTML)};o(t);for(var i=ke(t);i&&r.length<15;)o(i),i=ke(i);jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_load_field",field:r,form_id:E,nonce:frmGlobal.nonce},success:function(e){return function(e,t,n){var r,o;if(0===(e=e.replace(/^\s+|\s+$/g,"")).indexOf("{")){for(r in e=JSON.parse(e)){jQuery("#frm_field_id_".concat(r)).replaceWith(e[r]);var i=document.getElementById("frm_field_id_".concat(r));i&&(i.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),i.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")})),V("#frm_field_id_".concat(r,".edit_field_type_divider ul.frm_sorting")),X(document.getElementById("frm_field_id_".concat(r)))}((o=t.nextAll(".frm_field_loading:not(.frm_load_now)")).length||(o=jQuery(document.getElementById("frm-show-fields")).find(".frm_field_loading:not(.frm_load_now)")).length)&&Ee(o.attr("id")),ci(),Dn(),Ie();var a=new Event("frm_ajax_loaded_field",{bubbles:!1});a.frmFields=n.map(function(e){return JSON.parse(e)}),document.dispatchEvent(a)}else jQuery(".frm_load_now").removeClass(".frm_load_now").html("Error")}(e,n,r)}})}function ke(e){var t;return e.nextElementSibling?e.nextElementSibling:null===(t=e.parentNode)||void 0===t||null===(t=t.closest(".frm_field_box"))||void 0===t||null===(t=t.nextElementSibling)||void 0===t?void 0:t.querySelector(".form-field")}function Ae(){var e=jQuery(this);if(e.hasClass("disabled"))return!1;var t=e.closest(".frmbutton"),n=t.attr("id");if(t.hasClass("frm_at_limit"))return Se(),!1;if(!pe(n)){var r=0;"summary"===n&&(r=b.children('li[data-type="break"]').length>0?1:0);var o=E;return jQuery.ajax({type:"POST",url:ajaxurl,data:_e(n,0,o,r),success:function(e){Le(e);var t=ye(e);t&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:e,fieldId:t,fieldType:n,form_id:o})},error:he}),!1}}function Se(){var e=document.querySelector(".frm_wrap");if(e){var t=document.createElement("a");t.setAttribute("data-frmverify",I("This field type has reached its limit.","formidable")),e.append(t),t.click(),t.remove();var n=document.getElementById("frm-confirmed-click");n&&(n.style.display="none")}}function Le(e){document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var t=Ge(e),n=b[0].querySelector(".edit_field_type_submit");n?jQuery(n.closest(".frm_field_box:not(.form-field)")).before(t):b.append(t),We(e,!0),t.each(function(){$(this.querySelector("ul.frm_sorting")),X(this.querySelector(".form-field"),".frm-move")})}function Ie(){var e=!0,t=document.querySelectorAll(".frmjs_prod_field_opt_cont");b.find("li.edit_field_type_product").length>1&&(e=!1);for(var n=0;n<t.length;n++)t[n].classList.toggle("frm_hidden",e)}function Be(){var e=jQuery(this).closest("li.form-field"),t=this.getAttribute("frm-target-row-id");if(null!=t&&t.startsWith("frm_field_group_")||function(e){if(e.classList.contains("frm-page-collapsed"))return!1;var t=e.closest("li.frm_field_box:not(.form-field)");return!t||ie(jQuery(t.querySelector("ul"))).length<12}(e.get(0))){Ne();var n,r=e.data("fid"),o=function(e){var t=[];return jQuery(document.getElementById("frm_field_id_".concat(e))).find("li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)").each(function(){t.push(jQuery(this).data("fid"))}),t}(r);return null!==t&&(n=this.getAttribute("frm-field-order")),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_duplicate_field",field_id:r,form_id:E,children:o,nonce:frmGlobal.nonce},success:function(o){var i,a,l;if(null!==t&&null!==(a=document.getElementById(t)))return l=ve(o),jQuery(a).append(l),X(l.get(0),".frm-move"),null!==n&&a.lastElementChild.setAttribute("frm-field-order",n),jQuery(a).trigger("frm_added_duplicated_field_to_row",{duplicatedFieldHtml:o,originalFieldId:r}),We(o,!1),void qe(e.get(0),l.get(0));e.siblings("li.form-field").length?(l=ve(o),e.after(l),ae(e),X(l.get(0),".frm-move")):(l=Ge(o),e.parent().parent().after(l),$(l.get(0).querySelector("ul.frm_sorting")),X(l.get(0).querySelector("li.form-field"),".frm-move")),Er(),We(o,!1),Ce(r,o),Ar(l.find(".start_divider")),null===(i=e[0].querySelector(".frm-dropdown-menu.dropdown-menu-right"))||void 0===i||i.classList.remove("show"),qe(e.get(0),l.get(0))}}),!1}M(B(I("You can only have a maximum of %1$d fields in a field group. Delete or move out a field from the group and try again.","formidable"),12))}function qe(e,t){var n,r=e.closest(".frm-field-group-hover-target");if(r&&Qe(r.parentElement)){var o=e.dataset.fid,i=null===(n=document.getElementById("frm_classes_".concat(o)))||void 0===n?void 0:n.value;if(i&&(i=i.replace("frm_first",""),!t.className.includes(i))){t.className+=" ".concat(i);var a=document.getElementById("frm_classes_".concat(t.dataset.fid));a&&(a.value=i)}}}function Ce(e,t){var n=document.getElementById("frm-single-settings-".concat(e));if(null!==n){var r=jQuery(t).attr("data-fid");if(void 0!==r){var o=document.getElementById("frm-single-settings-".concat(r));if(null!==o){var i=["name","required","unique","read_only","placeholder","description","size","max","format","prepend","append","separate_value"];n.querySelectorAll('input[name^="field_options["], textarea[name^="field_options["]').forEach(function(t){var n,a=((n=t.name.substr(14).split("_")).pop(),n.join("_"));if("options"!==a){if(i.includes(a)){var l=t.matches("input")?"input":"textarea",s=o.querySelector("".concat(l,'[name="field_options[').concat(a,"_").concat(r,']"]'));null!==s&&("checkbox"===t.type?t.checked!==s.checked&&jQuery(s).trigger("click"):"text"!==t.type&&"textarea"!==l||t.value!==s.value&&(s.value=t.value,jQuery(s).trigger("change")))}}else!function(e,t,n,r){var o=e.name.substr(23+"".concat(n).length),i="field_options[options_".concat(r,"]").concat(o),a=t.querySelector('input[name="'.concat(i,'"]'));null!==a&&a.value!==e.value&&(a.value=e.value,jQuery(a).trigger("change"))}(t,o,e,r)});var a=n.querySelector('input[name="default_value_'.concat(e,'"]'));if(null!==a){var l=o.querySelector('input[name="default_value_'.concat(r,'"]'));null!==l&&a.value!==l.value&&(l.value=a.value,jQuery(l).trigger("change"))}}}}}function Ne(){var e=document.querySelector(".frm-field-settings-open");null!==e&&(e.classList.remove("frm-field-settings-open"),jQuery(document).off("click","#frm_builder_page",Te),jQuery(".frm-field-action-icons .dropdown.open").removeClass("open"))}function Te(e){jQuery(e.originalEvent.target).closest(".frm-field-action-icons").length||Ne()}function Oe(e){var t=Boolean(e.ctrlKey||e.metaKey||e.shiftKey);jQuery(O).toggleClass("frm-multiselect-key-is-down",t),function(e){if(!y.classList.contains("frm-dragging-field")&&null===document.querySelector(".frm-field-group-hover-target .frm-field-settings-open")){var t=document.elementFromPoint(e.clientX,e.clientY);if(null!==t&&!t.classList.contains("edit_field_type_divider")){var n=t.closest("ul.frm_sorting");if(null!==n&&!n.classList.contains("start_divider")&&"frm-show-fields"!==n.id){var r=Fe();!1===r||jQuery(r).is(n)||fn(),le(jQuery(n),ie(jQuery(n)).length),n.classList.add("frm-field-group-hover-target"),jQuery("#wpbody-content").on("mousemove",De)}}}}(e)}function Fe(){var e=document.getElementById("frm_field_group_controls");null!==e&&(e.style.display="none");var t=document.querySelector(".frm-field-group-hover-target");return null!==t&&(jQuery("#wpbody-content").off("mousemove",De),t.classList.remove("frm-field-group-hover-target"),t)}function De(e){var t=document.elementFromPoint(e.clientX,e.clientY);null!==t&&null!==t.closest("#frm-show-fields")||(Fe(),z())}function Me(e){vn(),setTimeout(function(){var t=document.querySelector(".dropdown .frm-dropdown-menu.show");if(null!==t){null===t.getAttribute("aria-label")&&t.setAttribute("aria-label",I("More Options","formidable")),0===t.children.length&&function(e,t){var n=t?"_field_group":"_field",r=[ze(t),Re(t)];t||r.push({class:"frm_select",icon:"frm_settings_icon",label:I("Field Settings","formidable")}),r.forEach(function(t){var r=document.createElement("div");r.classList.add("frm_more_options_li","dropdown-item");var o=document.createElement("a");o.classList.add(t.class+n),o.setAttribute("href","#"),zt(o);var i=document.createElement("span");i.textContent=t.label,o.innerHTML='<svg class="frmsvg"><use href="#'.concat(t.icon,'"></use></svg>'),o.append(document.createTextNode(" ")),o.append(i),r.append(o),e.append(r)})}(t,!0===e);var n=jQuery(t);n.offset().left>jQuery(window).width()-n.outerWidth()?t.style.left="".concat(-n.outerWidth(),"px"):y&&n.offset().left<y.getBoundingClientRect().left&&(t.style.right="auto",t.style.left="0");var r=t.firstElementChild.querySelector("a");r&&r.focus()}},0)}function Pe(){Me(!0)}function He(e){var t=e.target.closest(".frm-section-collapsed");t&&("show"===e.type?t.style.zIndex=3:t.style.zIndex=1)}function ze(e){var t={class:"frm_delete",icon:"frm_delete_icon"};return t.label=I(e?"Delete Group":"Delete","formidable"),t}function Re(e){var t={class:"frm_clone",icon:"frm_clone_icon"};return t.label=I(e?"Duplicate Group":"Duplicate","formidable"),t}function Ge(e){var t=c();"string"==typeof e?t.innerHTML=e:t.append(e);var n=jQuery();return Array.from(t.children).forEach(function(e){n=n.add(jQuery("<li>").addClass("frm_field_box").html(jQuery("<ul>").addClass("frm_grid_container frm_sorting").append(e)))}),n}function Ue(e){var t=s("ul",{className:"frm_grid_container frm_sorting"}),n=s("li",{className:"frm_field_box",child:t});e.replaceWith(n),t.append(e),$(t),X(n,".frm-move")}function We(e,t){var n,r,o=/id="(\S+)"/.exec(e),i=document.getElementById(o[1]),l="#".concat(o[1],".edit_field_type_divider ul.frm_sorting.start_divider"),s=jQuery(l),d=i.getAttribute("data-type");n=e,(r=c()).innerHTML=n,r.querySelectorAll(".form-field").forEach(Ve);var u,f,m=!1;if(Po(),V(l),"quantity"===d&&function(e){var t=e.getAttribute("data-fid"),n=document.getElementById("field_options[product_field_".concat(t,"]"));null!==n&&(nt(n),oo(document.getElementById("frm-single-settings-".concat(t))))}(i),"product"!==d&&"quantity"!==d||Ie(),s.length)s.parent(".frm_field_box").children(".frm_no_section_fields").addClass("frm_block");else{var _=jQuery(i).closest("ul.frm_sorting.start_divider");_.length&&(Ar(_),m=!0)}e.includes("frm-collapse-page")&&Dn(),f="frm-newly-added",(u=i).classList?u.classList.add(f):u.className+=" ".concat(f),setTimeout(function(){i.classList.remove("frm-newly-added")},1e3);var p,g=i.querySelector("#frm-last-row-fields-order");if(g&&((p=JSON.parse(g.value))&&"object"===a(p)&&Object.keys(p).forEach(function(e){var t=document.querySelector('input[name="field_options[field_order_'.concat(e,']"]'));t&&(t.value=p[e])})),t){var y=i.getBoundingClientRect(),v=document.getElementById("post-body-content");y.top>=0&&y.left>=0&&y.right<=(window.innerWidth||document.documentElement.clientWidth)&&y.bottom<=(window.innerHeight||document.documentElement.clientHeight)||v.scroll({top:v.scrollHeight,left:0,behavior:"smooth"}),!1===m&&Ar(s)}Ke(),ci(),document.getElementById("frm-show-fields").classList.remove("frm-over-droppable"),function(e){var t=document.getElementById(e);null!=t&&t.dataset.limit&&An(e)>=t.dataset.limit&&t.classList.add("frm_at_limit")}(d),i.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),i.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")});var h=new Event("frm_added_field",{bubbles:!1});h.frmField=i,h.frmSection=l,h.frmType=d,h.frmToggles=m,document.dispatchEvent(h)}function Ve(e){if(e.dataset.fid){var t=document.getElementById("draft_fields");t&&(""===t.value?t.value=e.dataset.fid:t.value.split(",").includes(e.dataset.fid)||(t.value+=",".concat(e.dataset.fid)))}}function $e(e){jQuery("#new_fields .frm-single-settings").addClass("frm_hidden"),jQuery("#frm-options-panel > .frm-single-settings").removeClass("frm_hidden"),Ke(e)}function Ke(e){jQuery("li.ui-state-default.selected").removeClass("selected"),jQuery(".frm-show-field-settings.selected").removeClass("selected"),e||vn()}function Je(){var e=this.value,t=function(e){var t,n=[],r=e.split(""),o=r.length,a=["{","[","("],l={"}":"{",")":"(","]":"["},s=!1;for(t=0;t<o;t++)a.includes(r[t])?n.push(r[t]):Object.hasOwn(l,r[t])&&n.pop()!==l[r[t]]&&(s=!0);return n.length>0||s?"".concat(i.unmatched_parens,"\n\n"):""}(e);t+=function(e,t){var n=function(e,t){var n="";return function(e){return jQuery(e).siblings('label[for^="calc_type"]').children("input").prop("checked")}(t)||/\[(date|time|email|ip)\]/.test(e)&&(n="".concat(i.text_shortcodes,"\n\n")),n}(e,t);return n+=function(e){var t="";return/\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g.test(e)&&(t+="".concat(i.view_shortcodes,"\n\n")),t}(e)}(e,this),""!==t&&M("".concat(e,"\n\n").concat(t))}function Xe(e,t){for(var n=!1,r=0;r<t.length;r++){var o=document.getElementsByName(Ye(t[r],e.fieldId));if(o.length&&jQuery(o[0]).val()){n=!0;break}}return n}function Ye(e,t){var n=e.indexOf("]");return"field_options".concat(e.substring(0,n),"_").concat(t).concat(e.substring(n))}function Ze(e,t){var n=jQuery(e).closest(".frm-single-settings"),r=n.find(".frm-calc-field");if(t||r.length&&""!==r.val()&&!r.is(":hidden")){var o=function(e){var t=jQuery(e).find(".frm_code_list");return 1===t.length&&t.hasClass("frm_js_summary_list")}(e),i=n.find('input[name="frm_fields_submitted[]"]').val(),a=function(e,t){var n=e.querySelector(".frm_code_list"),r=JSON.parse(n.getAttribute("data-exclude"));if(t){var o=function(){for(var e=[],t=document.getElementsByClassName("frm_include_extras_field"),n=0;n<t.length;n++)t[n].checked&&e.push(t[n].value);return e}();if(o.length)for(var i=0;i<r.length;i++)o.includes(r[i])&&(r.splice(i,1),i--)}return r}(t?e:document.getElementById("frm-calc-box-".concat(i)),o),l=function(e){var t=[];if(!Array.isArray(e))return t;for(var n=0;n<e.length;n++)e[n].startsWith("[")&&(t.push(e[n]),e.splice(n,1),n--);return t}(a),s=tt(),c=document.getElementById("frm-calc-list-".concat(i));c.innerHTML="";for(var u=0;u<s.length;u++)if(!(null!=a&&a.includes(s[u].fieldType)||l.length&&Xe(s[u],l))){var f=document.createElement("a");f.setAttribute("href","#"),f.setAttribute("data-code",s[u].fieldId),f.classList.add("frm_insert_code"),f.append(d(s[u].fieldName)),f.append(d({className:"frm-text-sm frm-text-grey-500",text:"[".concat(s[u].fieldId,"]")}));var m=document.createElement("li");m.classList.add("frm-field-list-".concat(i)),m.classList.add("frm-field-list-".concat(s[u].fieldType)),m.append(f),c.append(m)}}}function et(){Ze(jQuery(".frm-inline-modal.postbox:has(.frm_js_summary_list)")[0],!0)}function tt(e){var t,n=[],r=document.querySelectorAll("li.frm_field_box"),o=void 0!==e;for(t=0;t<r.length;t++)if(!o||r[t].getAttribute("data-ftype")===e){var i=r[t].getAttribute("data-fid");i&&n.push({fieldId:i,fieldName:ot("frm_name_".concat(i)),fieldType:ot("field_options_type_".concat(i)),fieldKey:ot("field_options_field_key_".concat(i))})}return wp.hooks.applyFilters("frm_admin_get_field_list",n,e,r)}function nt(e){var t,n,r,o=[],i=function(e){for(var t=e.querySelectorAll('[type="checkbox"]:checked'),n=[],r=0;r<t.length;r++)n.push(t[r].value);return n}(e),a=e.getAttribute("data-frmfname"),l=tt("product"),s=tt("quantity"),c="SELECT"===e.tagName,d=1===s.length&&1===l.length;for(c&&(i=e.getAttribute("data-frmcurrent")),t=0;t<l.length;t++)r=l[t].fieldId.toString(),n=d||i.includes(r),c?(n=n?" selected":"",o.push('<option value="'.concat(r,'"').concat(n,">").concat(l[t].fieldName,"</option>"))):(n=n?" checked":"",o.push('<label class="frm6">'),o.push('<input type="checkbox" name="'.concat(a,'" value="').concat(r,'"').concat(n,"> ").concat(l[t].fieldName)),o.push("</label>"));e.innerHTML=o.join("")}function rt(){for(var e=document.querySelectorAll(".frmjs_prod_field_opt"),t=0;t<e.length;t++)nt(e[t])}function ot(e){var t=document.getElementById(e);return null!==t?t.value:""}function it(){var e,t,n,r,o,i,a,l,s,c=this.value,d=document.getElementById(this.getAttribute("data-changeme")),u=this.getAttribute("data-changeatt");null!==d&&(null!==u?"SELECT"===d.tagName&&"placeholder"===u?""===(e=d.options[0]).value?e.innerHTML=c:ur(d,c):"class"===u?(n=d,l=" ".concat((r=this).value),void 0!==(s=n.getAttribute("data-fid"))&&(r.classList.contains("field_options_align")?l+=" ".concat(document.getElementById("frm_classes_".concat(s)).value):r.classList.contains("frm_classes")&&null!==(a=document.getElementById("field_options_align_".concat(s)))&&(l+=" ".concat(a.value))),l=(l+=" ").replace(" block "," vertical_radio ").replace(" inline "," horizontal_radio "),""===(o=0===(o=n.className.split(" frmstart ")[1]).indexOf("frmend ")?"":o.split(" frmend ")[0]).trim()?(i=" frmstart frmend ",n.className.includes(i)||(i=" frmstart frmend "),l=" frmstart ".concat(l.trim()," frmend ")):(i=o.trim(),l=l.trim()),n.className=n.className.replace(i,l)):"range"===(t=d).type&&t.parentNode.classList.contains("frm_range_container")?function(e,t,n){if(frmGlobal.proIncludesSliderJs){var r={field:e,att:t,newValue:n};wp.hooks.doAction("frm_update_slider_field_preview",r)}else{var o;if("value"===t?(""===n&&(n=at(e)),e.value=n):e.setAttribute(t,n),["value","min","max"].includes(t))"max"!==t&&"min"!==t||""!==(o=e.id,document.querySelector('input[data-changeme="'.concat(o,'"][data-changeatt="value"]')).value)||(e.value=at(e)),e.parentNode.querySelector(".frm_range_value").textContent=e.value}}(d,u,c):d.setAttribute(u,c):0===d.id.indexOf("setup-message")?""!==c&&(d.innerHTML='<input type="text" value="" disabled />'):(d.innerHTML=_r(c),"TEXTAREA"===d.nodeName&&d.classList.contains("wp-editor-area")&&jQuery(d).trigger("change"),d.classList.contains("frm_primary_label")&&"break"===d.nextElementSibling.getAttribute("data-ftype")&&(d.nextElementSibling.querySelector(".frm_button_submit").textContent=c)))}function at(e){var t=parseFloat(e.getAttribute("max")),n=parseFloat(e.getAttribute("min"));return(t-n)/2+n}function lt(){var e=this.getAttribute("data-fid"),t="";["field_options_max_","frm_format_"].forEach(function(n){var r=document.getElementById(n+e);r&&(t+=r.value)});var n=document.getElementsByName("field_options[type_".concat(e,"]"))[0];"text"===n.options[n.selectedIndex].value&&ct(""!==t,".frm_invalid_msg".concat(e))}function st(){var e=this.id.replace("frm_","").replace("req_field_",""),t=this.checked,n=jQuery("#field_label_".concat(e," .frm_required"));if(ct(t,".frm_required_details".concat(e)),t){var r=jQuery('input[name="field_options[required_indicator_'.concat(e,']"]'));""===r.val()&&r.val("*"),n.removeClass("frm_hidden")}else n.addClass("frm_hidden")}function ct(e,t){var n=jQuery(t);if(e)n.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");else{var r=n.fadeOut("fast").closest(".frm_validation_box"),o=r.css("display","block").children(":not(".concat(t,"):visible")).length;r.css("display",""),0===o&&n.closest(".frm_validation_msg").fadeOut("fast")}}function dt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(".frm_unique_details".concat(e));if(this.checked){t.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");var n=jQuery(".frm_unique_details".concat(e," input"));""===n.val()&&n.val(i.default_unique)}else{var r=t.fadeOut("fast").closest(".frm_validation_box"),o=r.css("display","block").children(":not(.frm_unique_details".concat(e,"):visible")).length;r.css("display",""),0===o&&t.closest(".frm_validation_msg").fadeOut("fast")}}function ut(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(this).val(),n=jQuery(document.getElementById("frm_field_id_".concat(e)));if(ct(""!==t,".frm_conf_details".concat(e)),""!==t){var r=jQuery(".frm_validation_box .frm_conf_details".concat(e," input"));""===r.val()&&r.val(i.default_conf),function(e){var t=document.getElementsByName("field_options[type_".concat(e,"]"))[0].value;ft(document.getElementById("field_description_".concat(e)),"field_options[description_".concat(e,"]"),i["enter_".concat(t)]),ft(document.getElementById("conf_field_description_".concat(e)),"field_options[conf_desc_".concat(e,"]"),i["confirm_".concat(t)])}(e),"inline"===t?n.removeClass("frm_conf_below").addClass("frm_conf_inline"):"below"===t&&n.removeClass("frm_conf_inline").addClass("frm_conf_below"),jQuery(".frm-conf-box-".concat(e)).removeClass("frm_hidden")}else jQuery(".frm-conf-box-".concat(e)).addClass("frm_hidden"),setTimeout(function(){n.removeClass("frm_conf_inline frm_conf_below")},200)}function ft(e,t,n){e.innerHTML===i.desc&&(e.innerHTML=n,document.getElementsByName(t)[0].value=n)}function mt(e){var t=JSON.parse(this.getAttribute("data-opts"));return e.preventDefault(),document.getElementById("frm_bulk_options").value=t.join("\n"),!1}function _t(){var e,t,n,r=jQuery(this).closest(".frm-single-settings").data("fid"),o=jQuery("#frm_field_".concat(r,"_opts .frm_option_template")).prop("outerHTML"),i=jQuery(this).data("opttype"),a=0,l="000",s=function(e){for(var t=0,n=0,r=jQuery("#frm_field_".concat(e,"_opts li")),o=0;t<r.length;t++){if(n=r[t].getAttribute("data-optkey"),1===r.length)return n;"000"!==n&&(n=n.replace("other_",""),n=parseInt(n,10)),!isNaN(o)&&(n>o||"000"===o)&&(o=n)}return o}(r);if(s!==l&&(a=s+1),"other"===i){document.getElementById("other_input_".concat(r)).value=1;var c=jQuery(this).data("ftype");"radio"!==c&&"select"!==c||jQuery(this).fadeOut("slow");var d={action:"frm_add_field_option",field_id:r,opt_key:a,opt_type:i,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,d,function(e){jQuery(document.getElementById("frm_field_".concat(r,"_opts"))).append(e),ir(r)})}else{o=(o=(o=(o=(o=o.replace(new RegExp('optkey="'.concat(l,'"'),"g"),'optkey="'.concat(a,'"'))).replace(new RegExp("-".concat(l,"_"),"g"),"-".concat(a,"_"))).replace(new RegExp("-".concat(l,'"'),"g"),"-".concat(a,'"'))).replace(new RegExp("\\[".concat(l,"\\]"),"g"),"[".concat(a,"]"))).replace("frm_hidden frm_option_template",""),Di(r,o={newOption:o});var u=this.closest(".frm_single_option");u?u.after(o.newOption):jQuery("#frm_field_".concat(r,"_opts")).append(o.newOption),ir(r)}null==(n=(e=this).classList.contains("frm-add-option-legacy")?null===(t=e.closest(".frm-collapse-me"))||void 0===t?void 0:t.querySelector(".frm_sortable_field_opts"):e.closest(".frm_sortable_field_opts"))||n.querySelectorAll(".frm_remove_tag.frm_disabled").forEach(function(e){return e.classList.remove("frm_disabled")}),Po()}function pt(){gt(jQuery(this).closest(".frm-single-settings").data("fid"),this.value)}function gt(e,t){var n=jQuery(".frm_multiple_cont_".concat(e));"select"===t?n.fadeIn("fast"):n.fadeOut("fast")}function yt(){var e=jQuery(this).closest(".frm-single-settings").data("fid");qi(jQuery(".field_".concat(e,"_option_key"))),jQuery(".field_".concat(e,"_option")).toggleClass("frm_with_key")}function vt(){var e=jQuery(this).closest(".frm-single-settings"),t=e.data("fid"),n=document.getElementById("frm_field_id_".concat(t));wt(jQuery(this)),qi(jQuery(".field_".concat(t,"_image_id"))),qi(jQuery(".frm_toggle_image_options_".concat(t))),qi(jQuery(".frm_image_size_".concat(t))),qi(jQuery(".frm_alignment_".concat(t))),qi(jQuery(".frm-add-other#frm_add_field_".concat(t)));var r=vr(t);if(r){bt(t,"inline"),ht(n);var o=or(t);n.classList.add("frm_image_options"),n.classList.add("frm_image_size_".concat(o)),e.find(".frm-bulk-edit-link").hide()}else n.classList.remove("frm_image_options"),ht(n),bt(t,"block"),e.find(".frm-bulk-edit-link").show();wp.hooks.doAction("frm_image_options_toggled",e[0],r)}function ht(e){e.classList.remove("frm_image_size_","frm_image_size_small","frm_image_size_medium","frm_image_size_large","frm_image_size_xlarge")}function bt(e,t){jQuery("#field_options_align_".concat(e)).val(t).trigger("change")}function jt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));Qt(),vr(e)&&(ht(t),t.classList.add("frm_image_options"),t.classList.add("frm_image_size_".concat(or(e))))}function wt(e){var t=e.closest(".frm-single-settings").data("fid");jQuery(".field_".concat(t,"_option")).trigger("change")}function Qt(){wt(jQuery(this))}function xt(e){var t,n=e.target.closest(".frm_image_preview_wrapper");if(null!==(t=wp)&&void 0!==t&&t.media&&(null==n||!n.dataset.upgrade)){e.preventDefault(),wp.media.model.settings.post.id=0;var r=wp.media.frames.file_frame=wp.media({multiple:!1,library:{type:["image"]}});r.on("select",function(){var e=r.state().get("selection").first().toJSON(),t=n.querySelector("img");t.setAttribute("src",e.url),t.classList.remove("frm_hidden"),t.removeAttribute("srcset"),n.querySelector(".frm_image_preview_frame").style.display="block",n.querySelector(".frm_image_preview_title").textContent=e.filename,n.querySelector(".frm_choose_image_box").style.display="none";var o=jQuery(n);o.siblings('input[name*="[label]"]').data("frmimgurl",e.url),o.find("input.frm_image_id").val(e.id).trigger("change"),wp.media.model.settings.post.id=0}),r.open()}}function Et(e){var t=jQuery(this).closest(".frm_image_preview_wrapper");e.preventDefault(),e.stopPropagation(),t.find("img").attr("src",""),t.find(".frm_image_preview_frame").hide(),t.find(".frm_choose_image_box").show(),t.find("input.frm_image_id").val(0).trigger("change")}function kt(){var e=jQuery(this).closest("li").find(".frm_form_fields select");this.checked?e.attr("multiple","multiple"):e.removeAttr("multiple")}function At(){var e=document.getElementById("dropform-search-input");null!==e&&setTimeout(function(){e.focus()},100)}function St(e){var t=e.target,n=t.closest(".frm_warning_style");jQuery(n).fadeOut(400,function(){return n.remove()});var r=t.dataset.action,o=new FormData;p(r,o)}function Lt(e){e.preventDefault()}function It(){var e,t,n=this.parentNode,r=n.parentNode,o=r.querySelectorAll("li:not(.frm_hidden)");2===o.length&&(null===(e=Array.from(o).find(function(e){return e!==n}).querySelector(".frm_remove_tag"))||void 0===e||e.classList.add("frm_disabled"));var i=this.getAttribute("data-fid");jQuery(n).fadeOut("fast",function(){wp.hooks.doAction("frm_before_delete_field_option",this),jQuery(n).remove(),jQuery(r).find(".frm_other_option").length<1&&(null!==(t=document.getElementById("other_input_".concat(i)))&&(t.value=0),jQuery("#other_button_".concat(i)).fadeIn("fast"))}),Po()}function Bt(){var e=jQuery(this);if(e.is(":checked")){var t,n=function(){e.off("mouseup",t)};t=function(){setTimeout(function(){e.prop("checked",!1)},0),n()},e.on("mouseup",t),e.one("mouseout",n)}}function qt(){this.value===i.new_option&&(this.setAttribute("data-value-on-focus",this.value),this.value="")}function Ct(e){return B(I("Are you sure you want to delete these %1$s selected field(s)?","formidable"),e)}function Nt(){var e=i.conf_delete,t=this.parentNode.parentNode.parentNode.parentNode.parentNode,n=t.parentNode,r=jQuery(this).closest("li.form-field"),o=r.data("fid");if("divider"===r.data("ftype")){var a=document.querySelectorAll(".frm-field-group-hover-target .start_divider .frm_field_box"),l=0;a.forEach(function(e){var t=e.querySelectorAll("li.form-field");t&&(l+=t.length)}),l&&(e=Ct(++l))}return n.classList.contains("frm-section-collapsed")||n.classList.contains("frm-page-collapsed")||("divider_section_only"===t.className&&(e=i.conf_delete_sec),this.setAttribute("data-frmverify",e),this.setAttribute("data-frmverify-btn","frm-button-red"),this.setAttribute("data-deletefield",o),Ne(),D(this)),!1}function Tt(){this.closest("li.form-field").click()}function Ot(){var e=document.querySelector(".frm-field-group-hover-target");if(null!==e){e.classList.add("frm-selected-field-group");var t=document.createElement("div");t.classList.add("frm-delete-field-groups","frm_hidden"),document.body.append(t),t.click()}}function Ft(){var e=document.querySelector(".frm-field-group-hover-target");if(null!==e){var t="frm_field_group_".concat(be()),n=document.createTextNode("");Ue(n);var r=jQuery(n).closest("li").get(0);r.classList.add("frm_hidden");var o=r.querySelector("ul");o.id=t,jQuery(e.closest("li.frm_field_box")).after(r);var i=ie(jQuery(e)),a=[],l=[],s=i.length,c={},d=0;jQuery(r).on("frm_added_duplicated_field_to_row",function(e,t){if(c[jQuery(t.duplicatedFieldHtml).attr("data-fid")]=t.originalFieldId,!(s>++d)){var n=jQuery(o),i=ie(n);l.forEach(function(e){e.remove()});for(var u=0;u<s;++u)n.append(n.children('li.form-field[frm-field-order="'.concat(u,'"]')));ae(i.first(),a),r.classList.remove("frm_hidden"),Er(),ie(n).each(function(){Ce(c[this.getAttribute("data-fid")],jQuery(this).prop("outerHTML"))})}}),i.each(function(e){var n=document.createElement("li");n.classList.add("frm_clone_field"),n.setAttribute("frm-target-row-id",t),n.setAttribute("frm-field-order",e),this.append(n),n.click(),l.push(n),a.push(an(ln(this.classList)))})}}function Dt(){var e=document.querySelector(".frm-field-group-hover-target");if(null!==e){Ke();var t=Pt(e.querySelector("li.form-field"));e.classList.add("frm-has-open-field-group-popup"),jQuery(document).on("click","#frm_builder_page",Mt);var n=c();n.style.position="relative",n.append(Ht(t,this)),this.parentNode.append(n);var r=n.querySelector(".frm-row-layout-option");r&&r.focus()}}function Mt(e){e.target.classList.contains("frm-custom-field-group-layout")||e.target.classList.contains("frm-cancel-custom-field-group-layout")||jQuery(e.target).closest("#frm_field_group_controls").length||jQuery(e.target).closest("#frm_field_group_popup").length||fn()}function Pt(e){var t=jQuery(e).closest("ul");return t.length?ie(t).length:wn()}function Ht(e,t){var n=document.getElementById("frm_field_group_popup");null===n?n=c():n.innerHTML="",n.id="frm_field_group_popup";var r,o=c();o.style.padding="0 24px 12px",o.append(((r=c()).classList.add("frm-row-layout-title"),r.textContent=I("Row Layout","formidable"),r));var i,a=function(e){var t=Xt();if(e>6)return t.append(Gt(e,"even")),t;if(5!==e&&t.append(Gt(e,"even")),e%2==1&&t.append(Gt(e,"middle")),e<6)t.append(Gt(e,"left")),t.append(Gt(e,"right"));else{var n=c();n.classList.add("frm_fourth"),t.prepend(n)}return t}(e),l=t.closest("ul.frm_sorting");return null!==l&&function(e,t){for(var n=t.children.length,r=0;r<n;++r){var o=t.children[r];if(Ut(o,e))return void o.classList.add("frm-active-row-layout")}}(l,a),o.append(a),n.append(o),n.append(document.createElement("hr")),e<=6&&n.append(((i=c()).textContent=I("Custom layout","formidable"),jQuery(i).prepend(Rt("frm_gear_svg")),i.classList.add("frm-custom-field-group-layout"),zt(i),i)),n.append(function(){var e=c();return e.textContent=I("Break into rows","formidable"),jQuery(e).prepend(Rt("frm_break_field_group_svg")),e.classList.add("frm-break-field-group"),zt(e),e}()),n}function zt(e,t){e.setAttribute("tabindex",0),e.setAttribute("role","button"),void 0!==t&&e.setAttribute("aria-label",t)}function Rt(e){var t=document.getElementById(e).cloneNode(!0);return t.id="",t}function Gt(e,t){var n,r=c();switch(r.classList.add("frm-row-layout-option"),zt(r,t),e){case 6:n="frm_half";break;case 5:n="frm_third";break;default:n=e>6?"frm_full":e%2==1?"frm_fourth":"frm_third"}return r.classList.add(n),r.setAttribute("layout-type",t),r.append(function(e,t){for(var n=Xt(),r=0;r<e;++r){var o=c();o.classList.add(Vt(e,t,r)),o.style.height="16px",o.style.background="#9EA9B8",o.style.borderRadius="1px",n.append(o)}return n}(e,t)),r}function Ut(e,t){return Wt(e)===Wt(t)}function Wt(e){var t;t=e.classList.contains("frm-row-layout-option")?jQuery(e).find(".frm_grid_container").children():ie(jQuery(e));var n=[];return t.each(function(){n.push(an(ln(this.classList)))}),n.join("-")}function Vt(e,t,n){if("even"===t)return $t(e,n);if("middle"===t){if(3===e)return 1===n?"frm6":"frm3";if(5===e)return 2===n?"frm4":"frm2"}else{if("left"===t)return 0===n?Jt(e):Kt(e);if("right"===t)return n===e-1?Jt(e):Kt(e)}return"frm12"}function $t(e,t){return e>6?"frm1":[2,3,4,6].includes(e)?sn(12/e):5===e&&void 0!==t?0===t?"frm4":"frm2":"frm12"}function Kt(e){switch(e){case 2:case 3:return"frm3";case 4:case 5:return"frm2";case 6:return"frm1";default:return"frm12"}}function Jt(e){switch(e){case 2:return"frm9";case 3:case 4:return"frm6";case 5:return"frm4";case 6:return"frm7";default:return"frm12"}}function Xt(){var e=c();return e.classList.add("frm_grid_container"),e}function Yt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t=this.getAttribute("layout-type");ae(ie(jQuery(e)).first(),t),fn()}}function Zt(){var e=en(),t=this.getAttribute("layout-type");ae(ie(e).first(),t),vn()}function en(){var e=jQuery(".frm-selected-field-group"),t=e.first();return e.not(t).each(function(){ie(jQuery(this)).each(function(){var e=this.parentNode;ie(t).last().after(this),jQuery(e).children("li.form-field").length||e.closest("li.frm_field_box").remove()})}),Er(),ae(ie(t).first()),t}function tn(){null===this.closest(".frm-merge-fields-into-row")&&nn(ie(jQuery(".frm-field-group-hover-target")))}function nn(e){var t=e.length,n=document.getElementById("frm_field_group_popup");n.innerHTML="";var r=c();r.style.padding="0 24px";var o=$t(5===t?6:t),i=c();if(i.style.padding="20px 0",i.classList.add("frm_grid_container"),5===t){var a=document.createElement("span");a.classList.add("frm1"),i.append(a)}var l=wn()>0&&an($t(t));!1!==l&&l>=12&&(l=Math.floor(12/t));for(var s=0;s<t;++s){var d=document.createElement("input");d.type="text",d.classList.add(o),d.classList.add("frm-custom-grid-size-input"),d.value=!1!==l?l:an(ln(e.get(s).classList)),i.append(d)}var u=c();u.classList.add("frm-builder-popup-heading"),u.textContent=I("Enter number of columns for each field","formidable");var f=c();f.classList.add("frm-builder-popup-subheading"),f.textContent=I("Layouts are based on a 12-column grid system","formidable"),r.append(u),r.append(f),r.append(i);var m=c();m.style.textAlign="right";var _,p=((_=on()).classList.add("button-secondary","frm-button-secondary"),_);p.textContent=I("Cancel","formidable"),p.classList.add("frm-cancel-custom-field-group-layout"),p.style.marginRight="10px";var g=function(){var e=on();return e.classList.add("button-primary","frm-button-primary"),e}();g.textContent=I("Save","formidable"),g.classList.add("frm-save-custom-field-group-layout"),m.append(p),m.append(g),r.append(m),n.append(r),setTimeout(function(){var e=n.querySelector("input.frm-custom-grid-size-input").focus();e&&e.focus()},0)}function rn(){nn(jQuery(".frm-selected-field-group li.form-field"))}function on(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button"),e.style.textDecoration="none",e}function an(e){switch(e){case"frm_half":return 6;case"frm_third":return 4;case"frm_two_thirds":return 8;case"frm_fourth":return 3;case"frm_three_fourths":return 9;case"frm_sixth":return 2;default:return 0===e.indexOf("frm")?parseInt(e.substr(3)):12}}function ln(e){for(var t=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"],n=0;n<t.length;++n){var r=t[n];if(e.contains(r))return r}return""}function sn(e){return"frm".concat(e)}function cn(){var e,t;e=document.querySelector(".frm-field-group-hover-target"),ie(t=jQuery(e)).each(function(e){0!==e&&t.parent().after(Ge(this)),function(e){ae(e,"clear")}(jQuery(this))}),fn()}function dn(){this.select()}function un(){jQuery(document.getElementById("frm_field_group_popup")).replaceWith(Ht(Pt(this),this))}function fn(){var e=document.getElementById("frm_field_group_popup");if(null!==e){var t=document.querySelector(".frm-has-open-field-group-popup");null!==t&&(t.classList.remove("frm-has-open-field-group-popup"),e.parentNode.remove()),jQuery(document).off("click","#frm_builder_page",Mt)}}function mn(){var e=[];jQuery(document.getElementById("frm_field_group_popup").querySelectorAll(".frm_grid_container input")).each(function(){e.push(parseInt(this.value))});var t=jQuery(document.getElementById("frm_field_group_controls"));t.length&&"none"!==t.get(0).style.display?ae(ie(jQuery(document.querySelector(".frm-field-group-hover-target"))).first(),e):(ae(ie(en()).first(),e),vn()),fn()}function _n(e){if(function(){var e=document.getElementById("frm-field-group-message");if(document.querySelectorAll(".edit_form_item:not(.edit_field_type_end_divider)").length<2)pn(e);else if(e)!function(e){e&&(e.classList.remove("frm_hidden"),e.classList.add("frm-fadein-up-back"))}(e);else{e=c({id:"frm-field-group-message",className:"frm-flex-center frm-fadein-up-back",children:[d({id:"frm-field-group-message-dismiss",className:"frm-flex-center",child:f({href:"#frm_close_icon"})})]}),document.getElementById("post-body-content").append(e);var t,n=((t=document.createElement("span")).classList.add("frm-field-group-message-text","frm-flex-center"),t.innerHTML=B(frm_admin_js.holdShiftMsg,'<span class="frm-meta-tag frm-flex-center"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-shift" viewBox="0 0 16 16"><path d="M7.3 2a1 1 0 0 1 1.4 0l6.4 6.8a1 1 0 0 1-.8 1.7h-2.8v3a1 1 0 0 1-1 1h-5a1 1 0 0 1-1-1v-3H1.7a1 1 0 0 1-.8-1.7L7.3 2zm7 7.5L8 2.7 1.7 9.5h2.8a1 1 0 0 1 1 1v3h5v-3a1 1 0 0 1 1-1h2.8z"/></svg>',"</span>"),t);e.prepend(n),document.getElementById("frm-field-group-message-dismiss").addEventListener("click",function(){pn(document.getElementById("frm-field-group-message"))})}}(),"ul"===e.originalEvent.target.nodeName.toLowerCase()){var t=document.querySelector(".frm-field-group-hover-target");if(t){var n=e.ctrlKey||e.metaKey,r=e.shiftKey,o=t.classList.contains("frm-selected-field-group"),i=function(){var e=jQuery(".frm-selected-field-group");if(e.length)return e;var t=gn();if(t){var n=t.closest("ul");if(n&&1===ie(jQuery(n)).length)return n.classList.add("frm-selected-field-group"),jQuery(n)}return jQuery()}(),a=i.length;if(n||r){var l=gn();if(null===l||jQuery(l).siblings("li.form-field").length||(l.parentNode.classList.add("frm-selected-field-group"),++a),n){if(o)return--a,t.classList.remove("frm-selected-field-group"),void yn(a);++a}else if(r&&!o){++a;var s=i.first();(s.parent().index()<jQuery(t.parentNode).index()?s.parent().nextUntil(t.parentNode):s.parent().prevUntil(t.parentNode)).each(function(){var e=jQuery(this).closest("li").find("ul.frm_sorting");e.hasClass("frm-selected-field-group")||(++a,e.addClass("frm-selected-field-group"))})}}else vn(),a=1;t.classList.add("frm-selected-field-group"),yn(a),document.querySelectorAll(".frm-selected-field-group").length<2||pn(document.getElementById("frm-field-group-message")),jQuery(document).off("click",vn),jQuery(document).on("click",vn)}}}function pn(e){e&&(e.classList.add("frm_hidden"),e.classList.remove("frm-fadein-up-back"))}function gn(){return document.getElementById("frm-show-fields").querySelector("li.form-field.selected")}function yn(e){$e(!0),e>=2||1===e&&ie(jQuery(document.querySelector(".frm-selected-field-group"))).length>1?function(){var e=document.getElementById("frm_field_multiselect_popup");if(null!==e)return e.classList.toggle("frm-unmergable",!bn()),e;(e=c()).id="frm_field_multiselect_popup",bn()||e.classList.add("frm-unmergable");var t=c();t.classList.add("frm-merge-fields-into-row"),t.textContent=I("Merge into row","formidable");var n=document.createElement("a");n.style.marginLeft="5px",n.classList.add("frm_icon_font","frm_arrowdown6_icon"),n.setAttribute("href","#"),t.append(n),e.append(t);var r=c();r.classList.add("frm-multiselect-popup-separator"),e.append(r);var o=c();o.classList.add("frm-delete-field-groups"),o.append(Rt("frm_trash_svg")),e.append(o),document.getElementById("post-body-content").append(e),jQuery(e).hide().fadeIn()}():hn(),Fe()}function vn(e){if(void 0!==e){if(null!==e.originalEvent.target.closest("#frm-show-fields"))return;if(e.originalEvent.target.classList.contains("frm-merge-fields-into-row"))return;if(null!==e.originalEvent.target.closest(".frm-merge-fields-into-row"))return;if(e.originalEvent.target.classList.contains("frm-custom-field-group-layout"))return;if(e.originalEvent.target.classList.contains("frm-cancel-custom-field-group-layout"))return}jQuery(".frm-selected-field-group").removeClass("frm-selected-field-group"),jQuery(document).off("click",vn),hn()}function hn(){var e=document.getElementById("frm_field_multiselect_popup");null!==e&&e.remove()}function bn(){var e=document.querySelectorAll(".frm-selected-field-group"),t=e.length;if(1===t)return!1;for(var n=0,r=0;r<t;++r){var o=e[r];if(null!==o.querySelector(".edit_field_type_break, .edit_field_type_hidden"))return!1;if((n+=ie(jQuery(o)).length)>12)return!1}return!0}function jn(e){if(null===e.originalEvent.target.closest("#frm_field_group_popup")&&!e.originalEvent.target.classList.contains("frm-custom-field-group-layout")){var t=Ht(wn(),document.querySelector(".frm-selected-field-group").firstChild);this.append(t)}}function wn(){var e=0;return jQuery(document.querySelectorAll(".frm-selected-field-group")).each(function(){e+=ie(jQuery(this)).length}),e}function Qn(){var e,t=(e=[],jQuery(".frm-selected-field-group > li.form-field").each(function(){e.push(this.dataset.fid)}),e),n=function(e){return function(t){t.preventDefault(),function(e){e.forEach(function(e){En(e)})}(e)}}(t),r=document.getElementById("frm_field_multiselect_popup");null!==r&&r.remove(),this.setAttribute("data-frmverify",Ct(t.length)),D(this);var o=document.getElementById("frm-confirmed-click");null==o||o.removeAttribute("data-deletefield"),jQuery(o).on("click",n),jQuery("#frm_confirm_modal").one("dialogclose",function(){jQuery(o).off("click",n)})}function xn(){En(this.getAttribute("data-deletefield"))}function En(e){var t=jQuery("#frm_field_id_".concat(e));kn(e),t.hasClass("edit_field_type_divider")&&t.find("li.frm_field_box[data-fid]").each(function(){kn(this.getAttribute("data-fid"))}),kr()}function kn(e){jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_delete_field",field_id:e,nonce:frmGlobal.nonce},success:function(){var t,n,r,o=jQuery(document.getElementById("frm_field_id_".concat(e))),i=jQuery("#frm-single-settings-".concat(e));i.is(":visible")&&(null===(t=document.querySelector(".frm-settings-panel .frm-tabs-navs ul > li:first-child"))||void 0===t||t.click(),document.querySelector("#frm-options-panel .frm-single-settings").classList.remove("frm_hidden")),function(e){var t=e[0].querySelectorAll(".frm-inline-modal[data-fills]");t.length&&t.forEach(function(e){e.classList.add("frm_hidden"),e.removeAttribute("data-fills"),e.closest("form").append(e)})}(i),i.remove(),o.fadeOut("slow",function(){var e,t=o.closest(".start_divider"),n=o.data("type"),r=o.siblings("li.form-field");if(r.length||(o.is(".edit_field_type_end_divider")?r.length=o.closest("li.form-field").siblings():e=o.closest("ul.frm_sorting").parent()),o.remove(),"break"===n?Dn():"product"===n&&(Ie(),rt()),r.length?ae(r.first()):e.remove(),0===jQuery("#frm-show-fields li").length||function(){if(b.get(0).childElementCount>1)return!1;var e=b.get(0).firstElementChild.firstElementChild.querySelectorAll("li.frm_field_box");return!(e.length>1)&&e[0].classList.contains("edit_field_type_submit")}()){var i=document.getElementById("frm_form_editor_container");i.classList.remove("frm-has-fields"),i.classList.add("frm-empty-fields")}else t.length&&Ar(t);z()}),o.length&&(n=o.data("type"),(r=document.getElementById(n))&&r.dataset.limit&&An(n)-1<r.dataset.limit&&r.classList.remove("frm_at_limit"),wp.hooks.doAction("frm_after_delete_field",o[0]))}})}function An(e){return document.getElementById("frm-show-fields").querySelectorAll('li.form-field[data-ftype="'.concat(e,'"]')).length}function Sn(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=E,n=document.getElementById("frm_logic_row_".concat(e)).querySelectorAll(".frm_logic_row");return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_logic_row",form_id:t,field_id:e,nonce:frmGlobal.nonce,meta_name:Ln(n,"frm_logic_".concat(e,"_")),fields:tt()},success:function(t){jQuery(document.getElementById("logic_".concat(e))).fadeOut("fast",function(){var n=document.getElementById("frm_logic_row_".concat(e));n.insertAdjacentHTML("beforeend",t);var r=n.querySelector(".frm_logic_row:last-child .frm-logic-rule-text");r&&(r.textContent=n.dataset.ruleText);var o=n.closest(".frm_logic_rows");o.style.height="auto",jQuery(o).fadeIn("fast")})}}),!1}function Ln(e,t,n){return e.length?parseInt(e[e.length-1].id.replace(t,""),10)+1:void 0!==n?n:0}function In(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=E,n=document.getElementById("frm_watch_lookup_block_".concat(e)).children;return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_watch_lookup_row",form_id:t,field_id:e,row_key:Ln(n,"frm_watch_lookup_".concat(e,"_")),nonce:frmGlobal.nonce},success:function(t){var n,r=jQuery(document.getElementById("frm_watch_lookup_block_".concat(e)));r.append(t),r.fadeIn("slow"),null===(n=document.getElementById("frm_watch_lookup_label_".concat(e)))||void 0===n||n.classList.remove("frm-force-hidden")}}),!1}function Bn(e){var t,n,r=jQuery(e).closest(".frm-single-settings").attr("data-fid"),o=jQuery(e).closest("ul").get(0).querySelectorAll(".field_".concat(r,"_option"));for(t in o)if(Object.hasOwn(o,t)&&(n=o[t]).id!==e.id&&n.value===e.value&&"true"!==n.getAttribute("data-duplicate"))return!0;return!1}function qn(){var e,t;null===this.getAttribute("data-value-on-load")&&(this.setAttribute("data-value-on-load",this.value),t=jQuery(this).closest(".frm-single-settings").attr("data-fid"),(e=document.createElement("input")).value=this.value,e.setAttribute("type","hidden"),e.setAttribute("name","optionmap[".concat(t,"][").concat(this.value,"]")),this.parentNode.append(e),void 0===A[t]&&(A[t]={}),A[t][this.value]=e),"true"===this.getAttribute("data-duplicate")&&(this.removeAttribute("data-duplicate"),Bn(this))?this.setAttribute("data-value-on-focus",this.getAttribute("data-value-on-load")):""===this.value&&i.new_option===this.getAttribute("data-value-on-focus")||this.setAttribute("data-value-on-focus",this.value)}function Cn(e){var t,n=e.closest(".frm_single_option");return e.parentElement.classList.contains("frm_single_option")?{newValue:n.querySelector('.frm_option_key input[type="text"]').value,newLabel:t=e.value}:(t=n.querySelector('input[type="text"]').value,{newValue:e.value,newLabel:t})}function Nn(){var e,t,n=function(e){var t=function(e){var t,n,r=null!==(t=null===(n=e.closest(".frm-single-settings").querySelector(".frm_toggle_sep_values"))||void 0===n?void 0:n.checked)&&void 0!==t&&t,o=e.closest(".frm_single_option");return r&&e.parentElement.classList.contains("frm_single_option")?{oldValue:o.querySelector('.frm_option_key input[type="text"]').getAttribute("data-value-on-focus"),oldLabel:e.getAttribute("data-value-on-focus")}:{oldValue:e.getAttribute("data-value-on-focus"),oldLabel:o.querySelector('input[type="text"]').getAttribute("data-value-on-focus")}}(e),n=t.oldValue,r=t.oldLabel,o=Cn(e);return{oldValue:n,oldLabel:r,newValue:o.newValue,newLabel:o.newLabel}}(this),r=n.oldValue,o=n.oldLabel,i=n.newValue,a=n.newLabel;if(r!==i||o!==a){var l=this.closest(".frm-single-settings"),s=l.getAttribute("data-fid"),c=this.getAttribute("data-value-on-load");if(Bn(this))return this.setAttribute("data-duplicate","true"),void(void 0!==A[s]&&void 0!==A[s][c]&&(A[s][c].value=c));void 0!==A[s]&&void 0!==A[s][c]&&(A[s][c].value=i);for(var d=[],u=O.querySelectorAll(".frm_logic_row"),f=u.length,m=0;m<f;m++){var _=u[m];if(_.querySelector(".frm_logic_field_opts").value===s){var p,g=_.id.split("_")[2],y=_.querySelector('select[name="field_options[hide_opt_'.concat(g,'][]"]')),v=void 0,h=void 0;(v=""===r?[]:y.querySelectorAll('option[value="'.concat(r,'"]'))).length||(v=y.querySelectorAll('option[value="'.concat(i,'"]'))).length||(null!==(p=l.querySelector(".frm_toggle_sep_values"))&&void 0!==p&&p.checked||(h=Tn(y,r)),h||(h=document.createElement("option"),y.append(h))),v.length&&(h=v[v.length-1]),h.setAttribute("value",i),h.textContent=a,d.includes(g)||d.push(g)}}for(e in d)Object.hasOwn(d,e)&&(t=d[e],oo(document.getElementById("frm-single-settings-".concat(t))))}}function Tn(e,t){for(var n=e.options,r=0;r<n.length;r++){var o=n[r];if(t===o.textContent)return o}return null}function On(){var e=this.id.replace("get_values_form_",""),t=document.getElementById("get_values_field_".concat(e)),n=this.getAttribute("data-fieldtype");if(""===this.value)t.options.length=1;else{var r=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_options_for_get_values_field",form_id:r,field_type:n,nonce:frmGlobal.nonce},success:function(e){t.innerHTML=e}})}}function Fn(){var e,t,n=this.name.replace("field_options[data_type_","").replace("]","");(e=document.getElementById("frm_add_watch_lookup_link_".concat(n)))&&(e=e.parentNode,"text"===this.value?null!==(t=document.getElementById("frm_watch_lookup_block_".concat(n)))&&(t.innerHTML="",e.classList.add("frm_hidden"),e.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.previousElementSibling.style.display="none"):e.classList.remove("frm_hidden"),gt(n,this.value))}function Dn(){var e,t,n=document.getElementsByClassName("frm-page-num");if(n.length>1)for(document.getElementById("frm-fake-page").style.display="block",e=0;e<n.length;e++)t=n[e].parentNode.parentNode.parentNode.classList,1===e?t.add("frm-first-page"):t.remove("frm-first-page"),n[e].textContent=e+1;else document.getElementById("frm-fake-page").style.display="none";wp.hooks.doAction("frm_renumber_page_breaks",n)}function Mn(){var e,t,n,r=jQuery(this).closest(".frm_field_box[data-ftype=break]");r.length?function(e){var t=Pn(e.get(0).parentNode.closest("li.frm_field_box").nextElementSibling);Hn(e,t)}(r):(e=document.getElementById("frm-fake-page"),t=document.getElementById("frm-show-fields").firstElementChild,n=Pn(t),"break"!==t.getAttribute("data-ftype")&&Hn(jQuery(e),n))}function Pn(e){var t,n;if(t=jQuery(),null===e)return t;n=e;do{if(null!==n.querySelector(".edit_field_type_break"))break;t=t.add(jQuery(n)),n=n.nextElementSibling}while(null!==n);return t}function Hn(e,t){var n,r=t.length,o=Math.min(r,3);if(e.hasClass("frm-page-collapsed"))for(e.removeClass("frm-page-collapsed"),t.removeClass("frm-is-collapsed"),n=0;n<o;n++)n===o-1?jQuery(t[n]).slideDown(150,function(){t.show()}):jQuery(t[n]).slideDown(150);else for(e.addClass("frm-page-collapsed"),t.addClass("frm-is-collapsed"),n=0;n<o;n++)n===o-1?jQuery(t[n]).slideUp(150,function(){t.css("cssText","display:none !important;")}):jQuery(t[n]).slideUp(150)}function zn(){this.parentNode.parentNode.parentNode.parentNode.classList.toggle("frm-section-collapsed")}function Rn(){this.classList.toggle("frm-collapsed");var e="true"===this.getAttribute("aria-expanded")||!1;this.setAttribute("aria-expanded",!e),Gn(this.nextElementSibling)}function Gn(e){if(e){var t=e.scrollHeight;t<=0||(t+=250,e.style.setProperty("--slide-height","".concat(t,"px")),e.style.setProperty("--slide-time","".concat(Math.ceil(.8*t),"ms")))}}function Un(){if(this.id){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0],t=this.id.replace("field_label_",""),n=document.getElementById("field_options_type_".concat(t)),r=n.value;void 0!==e&&(r=function(e){return"divider"===e?e="section":"range"===e?e="slider":"data"===e?e="dynamic":"form"===e&&(e="embed form"),e}(r="SELECT"===n.tagName?n.options[n.selectedIndex].text.toLowerCase():r.replace("_"," ")),setTimeout(function(){e.value.toLowerCase()===r?e.select():e.focus()},50))}}function Wn(){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0];void 0!==e&&setTimeout(function(){e.focus(),Vn(e)},50)}function Vn(e){var t=e.closest(".frm-collapse-me");null!==t&&t.previousElementSibling.classList.remove("frm-collapsed")}function $n(e){var t,n,r=e.target.classList;if(!r.contains("frm-collapse-page")&&!r.contains("frm-sub-label")&&null===e.target.closest(".dropdown")){if(null!==this.closest(".start_divider")&&e.stopPropagation(),this.classList.contains("edit_field_type_divider")){var o=e.originalEvent.target.closest("ul.frm_sorting");if(null!==o&&(o.classList.contains("edit_field_type_divider")||o.parentNode.parentNode.classList.contains("start_divider")))return}t=this,n=jQuery(t),t.className.includes("selected")||t.className.includes("edit_field_type_end_divider")&&n.closest(".edit_field_type_divider").hasClass("no_repeat_section")||(Ke(),n.addClass("selected"),function(e){var t,n,r=e.getAttribute("data-fid"),o=e.getAttribute("data-type"),i=document.querySelectorAll(".frm-single-settings:not(.frm_hidden)");for(n=0;n<i.length;n++)i[n].classList.add("frm_hidden");var a=document.getElementById("frm-single-settings-".concat(r));oo(a),o&&"quantity"===o&&nt(jQuery(a).find(".frmjs_prod_field_opt")[0]),null===(t=document.querySelector(".frm-settings-panel.frm-scrollbar-wrapper"))||void 0===t||t.scrollTo({top:0,behavior:"instant"}),a.classList.remove("frm_hidden"),document.getElementById("frm-options-panel-tab").click();var l=a.querySelector(".wp-editor-area");l&&frmDom.wysiwyg.init(l,{setupCallback:ro}),wp.hooks.doAction("frmShowedFieldSettings",e,a),function(e,t,n){var r;if(function(e){return wp.hooks.applyFilters("frm_fields_with_shortcode_popup",["html"]).includes(e)}(e)){var o="#frm-single-settings-".concat(t);if(!document.querySelector("".concat(o," .frm-show-box"))){null===(r=n.querySelector(".wp-editor-container"))||void 0===r||r.classList.add("frm_has_shortcodes");var i=function(){return frmDom.svg({href:"#frm_more_horiz_solid_icon",classList:["frm-show-box"]})};document.querySelectorAll("".concat(o," .frm_has_shortcodes textarea")).forEach(function(e){var t=d({className:"frm-with-right-icon"});e.parentNode.insertBefore(t,e),t.append(i()),t.append(e)})}}}(o,r,a)}(t))}}function Kn(e){var t=e.target;if("custom"===t.value){var n=t.dataset.fieldId,r=document.getElementById("frm-field-format-custom-".concat(n)).querySelector(".frm_format_opt");"international"!==r.value&&"currency"!==r.value&&"number"!==r.value||r.setAttribute("value","")}setTimeout(function(){t.querySelectorAll("option").forEach(function(e){e.selected&&e.classList.contains("frm_show_upgrade")&&(t.value="none")})},0)}function Jn(){var e=this.getAttribute("data-fid");Vn(document.getElementById("field_options_field_key_".concat(e)))}function Xn(){var e=jQuery(this).closest(".frm_field_box");e.find(".repeat_icon_links").removeClass("repeat_format repeat_formatboth repeat_formattext").addClass("repeat_format".concat(this.value)),"text"===this.value||"both"===this.value?(e.find(".frm_repeat_text").show(),e.find(".repeat_icon_links a").addClass("frm_button")):(e.find(".frm_repeat_text").hide(),e.find(".repeat_icon_links a").removeClass("frm_button"))}function Yn(){var e=this.value;""!==e&&(e<2||e>200)&&(M(i.repeat_limit_min),this.value="")}function Zn(){var e=this.value;""!==e&&(e<1||e>200)&&(M(i.checkbox_limit),this.value="")}function er(e,t){jQuery(e).closest(".frm_field_box").find(".frm_".concat(t,"_form_row .frm_repeat_label")).text(e.value)}function tr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=this.value,n=document.getElementById("frm_show_selected_fields_".concat(e)),r=document.getElementById("frm_show_selected_forms_".concat(e));jQuery(r).find("select").val(""),"form"===t?(r.style.display="inline",function(e){if(null!==e)for(;e.firstChild;)e.firstChild.remove()}(n)):(n.style.display="none",r.style.display="none",xr(t,e))}function nr(){var e=rr(this);if(e){var t=jQuery(this).closest(".frm_single_option");!function(e,t,n){var r=n.data("optkey"),o=yr(e),i=jQuery('label[for="field_'.concat(t,"-").concat(r,'"]')),a="field_options[options_".concat(e,"][").concat(r,"]"),l=jQuery('input[name="'.concat(a,'[label]"]'));if(i.length<1)return ir(e),void(n.find('input[name^="default_value_"]').is(":checked")&&l.length>0&&jQuery('select[name^="item_meta['.concat(e,']"]')).val(l.val()));var s,d=i.children("input");if(s=l.length<1?(l=jQuery('input[name="'.concat(a,'"]'))).val():o?jQuery('input[name="'.concat(a,'[value]"]')).val():l.val(),!(l.length<1)){var u=i[0].childNodes;if(vr(e)){var f=function(e,t,n){var r,o=e.find("img");o&&(r=o.attr("src"));var i=hr(t);return pr(n.val(),i,r)}(n,e,l),m=i.find(".frm_image_option_container");m.length>0?m.replaceWith(f):(u[u.length-1].nodeValue="",i.append(f))}else{var _=!1;u.forEach(function(t,n){if(!1===_)"INPUT"===t.tagName&&(_=n);else if(n===_+1){var r="";!function(e){var t=document.getElementsByName("field_options[image_options_".concat(e,"]")),n=Array.from(t).find(function(e){return e.checked&&"buttons"===e.value});return void 0!==n}(e)?t.nodeValue=" ".concat(l.val()):(r=c({className:"frm_label_button_container",text:" ".concat(l.val())}),i[0].replaceChild(r,t))}else t.remove()})}d.val(s),defaultVal=n.find('input[name^="default_value_"]'),d.prop("checked",!!defaultVal.is(":checked"))}}(e.fieldId,e.fieldKey,t)}}function rr(e){var t=jQuery(e).closest(".frm_sortable_field_opts");return!!t.length&&{fieldId:t.attr("id").replace("frm_field_","").replace("_opts",""),fieldKey:t.data("key")}}function or(e){var t,n=document.getElementById("field_options_image_size_".concat(e)),r="";return null!==n&&""!==(t=n.value)&&(r=t),r}function ir(e){var t=jQuery('[name^="item_meta['.concat(e,']"]'));if(!(t.length<1)){if(t.is("select")){var n=document.getElementById("frm_placeholder_".concat(e));null===n||""===n.value?dr(t[0],{sourceID:e}):dr(t[0],{sourceID:e,placeholder:n.value})}else{var r=fr(e);jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")).html("");for(var o=rr(jQuery("#frm_delete_field_".concat(e,"-000_container"))),i=jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")),a=vr(e),l=a?or(e):"",s=a?"frm_image_option frm_image_".concat(l," "):"",c=Oi(e),d="hidden"===t.attr("type")?t.data("field-type"):t.attr("type"),u=0;u<r.length;u++)i.append(cr(d,r[u],e,o.fieldKey,c,s))}lr(e)}}function ar(e,t){var n=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('input[value="'.concat(t,'"]'));return n?Cn(n):{newValue:t,newLabel:t}}function lr(e,t){for(var n=O.querySelectorAll(".frm_logic_row"),r=n.length,o=wp.hooks.applyFilters("frm_conditional_logic_field_options",function(e){var t=[],n=document.getElementById("frm_field_".concat(e,"_opts"));if(!n)return t;for(var r=n.querySelectorAll(".frm_single_option"),o=r.length,i=0;i<o;i++){var a=r[i];if(!a.classList.contains("frm_hidden")){var l=a.querySelector(".field_".concat(e,"_option"));t.push(l.value)}}return t}(e),{type:t,fieldId:e}),i=o.length,a=0;a<r;a++){var l=n[a];if(l.querySelector(".frm_logic_field_opts").value==e){for(var s=l.id.split("_")[2],c=l.querySelector('select[name="field_options[hide_opt_'.concat(s,'][]"]')),d=function(){var t,n=o[u],r=null===(t=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('.frm_option_key input[type="text"]'))||void 0===t?void 0:t.value;r||(r=n);var i=c.querySelector('option[value="'.concat(r,'"]')),a=ar(e,n),l=a.newValue,s=a.newLabel,d=document.querySelectorAll("#frm_field_".concat(e,"_opts input[data-value-on-focus]")),f=Array.from(d).find(function(e){return e.value===n});if(f){var m=f.dataset.valueOnFocus;if(m&&c.querySelector('option[value="'.concat(m,'"]')))return 1}sr(c,i,l,s)},u=i-1;u>=0;u--)d();var f=c.querySelector('option[value=""]');null!==f&&c.prepend(f)}}}function sr(e,t,n,r){null!==t||e.querySelector('option[value="'.concat(n,'"]'))||((t=frmDom.tag("option",{text:r})).value=n),e.prepend(t)}function cr(e,t,n,r,o,i){var a="",l=t.key.includes("other"),s="field_".concat(r,"-").concat(t.key),c="scale"===e?"radio":e,d='<input type="text" id="field_'.concat(r,"-").concat(t.key,'-otext" class="frm_other_input frm_pos_none" name="item_meta[other][').concat(n,"][").concat(t.key,']" value="" />');return this.getSingle=function(){return""!==(a=wp.hooks.applyFilters("frm_admin.build_single_option_template",a,{opt:t,type:e,fieldId:n,classes:i,id:s}))?a:'<div class="frm_'.concat(e," ").concat(e," ").concat(i,'" id="frm_').concat(e,"_").concat(n,"-").concat(t.key,'">\n\t\t\t\t\t<label for="').concat(s,'">\n\t\t\t\t\t\t<input type="').concat(c,'" name="item_meta[').concat(n,"]").concat("checkbox"===e?"[]":"",'" value="').concat(_r(t.saved),'" id="').concat(s,'"').concat(o?' data-price="'.concat(t.price,'"'):"").concat(t.checked?' checked="checked"':"",">\n\t\t\t\t\t\t").concat(_r(t.label),"\n\t\t\t\t\t</label>\n\t\t\t\t\t").concat(l?d:"","\n\t\t\t\t</div>")},this.getSingle()}function dr(e,t){if(null!==e){var n=t.sourceID,r=t.placeholder,o=Oi(n),i=t.other;!function(e){var t;if(void 0!==e.options)for(t=e.options.length-1;t>=0;t--)e.remove(t)}(e);for(var a=fr(n,e.id.includes("frm_field_logic_opt")),l=void 0!==r,s=0;s<a.length;s++){var c=a[s].label,d=a[s].key.includes("other");if(l&&""!==c?ur(e,r):l&&(c=r),l=!1,!d||i){var u=document.createElement("option");u.value=a[s].saved,u.innerHTML=_r(c),o&&u.setAttribute("data-price",a[s].price),e.append(u)}}}}function ur(e,t){var n=document.createElement("option"),r=e.firstChild;n.value="",n.innerHTML=t,null!==r?(r.before(n),e.selectedIndex=0):e.append(n)}function fr(e){var t,n,r,o,i,a,l=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=[],c=jQuery('input[name^="field_options[options_'.concat(e,']"]')).filter('[name$="[label]"], [name*="[other_"]'),d=Oi(e),u=hr(e),f=vr(e),m=yr(e);for(t=0;t<c.length;t++)c[t].name.indexOf("[000]")>0||(o=n=c[t].value,i=c[t].name.replace("field_options[options_".concat(e,"]["),"").replace("[label]","").replace("]",""),m&&(r=c[t].name.replace("[label]","[value]"),n=jQuery('input[name="'.concat(r,'"]')).val(),l&&""===o&&(o=""!==n?n:frm_admin_js.no_label)),f&&(o=pr(o,u,mr(c[t]))),a={saved:n,label:o=frmAdminBuild.hooks.applyFilters("frm_choice_field_label",o,e,c[t],f),checked:gr(c[t].id),key:i},d&&(r=c[t].name.replace("[label]","[price]"),a.price=jQuery('input[name="'.concat(r,'"]')).val()),s.push(a));return s}function mr(e){var t=jQuery(e).siblings(".frm_image_preview_wrapper");if(!t.length)return"";var n=t.find("img");return n.length?n.attr("src"):""}function _r(e){(e instanceof Element||e instanceof Document)&&(e=e.outerHTML);var t=jQuery.parseHTML(e).reduce(function(e,t){var n=frmDom.cleanNode(t);return"#text"===n.nodeName?e+n.textContent:e+n.outerHTML},"");return t!==e?_r(t):t}function pr(e,t,n){var r,o=e;o=_r(o),n?r=m({src:n,alt:o}):(r=c({className:"frm_empty_url"})).innerHTML=i.image_placeholder_icon;var a=t?" frm_label_with_image":"",l=s("span",{className:"frm_text_label_for_image_inner"});return l.innerHTML=o,s("span",{className:"frm_image_option_container".concat(a),children:[r,s("span",{className:"frm_text_label_for_image",child:l})]})}function gr(e){var t=jQuery("#".concat(e));if(0===t.length)return!1;var n=t.siblings("input[type=checkbox]");return n.length&&n.prop("checked")}function yr(e){return br("separate_value_".concat(e))}function vr(e){for(var t=!1,n=document.getElementsByName("field_options[image_options_".concat(e,"]")),r=0;r<n.length;r++)n[r].checked&&(t="0"!==n[r].value);return frmAdminBuild.hooks.applyFilters("frm_choice_field_images_as_options",t,e)}function hr(e){var t=!br("hide_image_text_".concat(e));return frmAdminBuild.hooks.applyFilters("frm_choice_field_showing_label_with_image",t,e)}function br(e){var t=document.getElementById(e);return null!==t&&t.checked}function jr(e){var t=e.closest(".frm-single-settings"),n=t.getAttribute("data-fid"),r=t.querySelector('[name="field_options[separate_value_'.concat(n,']"]')).checked;if(!r||e.name.endsWith("[value]")){var o=document.getElementById("frm_field_".concat(n,"_opts"));Array.from(o.querySelectorAll('input[type="text"]')).filter(function(t){return t.id!==e.id&&r===t.name.endsWith("[value]")&&t.value===e.value}).length&&M(B(I('Duplicate option value "%s" detected',"formidable"),_r(e.value)))}}function wr(){var e=this.value;if(e){var t=this.parentNode.id.replace("frm_logic_","").split("_"),n=t[0],r=t[1],o=document.getElementById("frm_field_id_".concat(e)).getAttribute("data-ftype"),i=document.getElementById("frm_show_selected_values_".concat(n,"_").concat(r)),a="field_options[hide_opt_".concat(n,"][]"),l="frm_field_logic_opt_".concat(n),s=!1,c="select"===o||"checkbox"===o||"radio"===o,d="text"===o||"email"===o||"phone"===o||"url"===o||"number"===o;if(c&&null!==document.getElementById("frm_has_hidden_options_".concat(e))&&(c=!1),c||d){var u=document.querySelector("#frm_logic_".concat(n,"_").concat(r,' [name="field_options[hide_field_cond_').concat(n,'][]"]')).value;i.innerHTML="";var f=c&&!["LIKE","not LIKE","LIKE%","%LIKE"].includes(u);f?s=document.createElement("select"):(s=document.createElement("input")).type="text",s.name=a,s.id="".concat(l,"_").concat(r),i.append(s),f&&dr(document.getElementById(s.id),{sourceID:e,placeholder:"",other:!0})}else{var m=this.getAttribute("data-type");frmGetFieldValues(e,n,r,m,void 0,function(){var e=new CustomEvent("frm_logic_options_loaded");e.frmData={valueFieldType:o,fieldID:n,metaKey:r},document.dispatchEvent(e)})}}}function Qr(){var e=this.value;e&&xr(e,jQuery(this).closest(".frm-single-settings").data("fid"))}function xr(e,t){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_field_selection",field_id:t,form_id:e,nonce:frmGlobal.nonce},success:function(e){var n=jQuery("#frm_show_selected_fields_".concat(t));n.toggleClass("frm6",!e.includes("frm-inline-message")),n.html(e).show()}})}function Er(){var e=this;return this.initOnceInAllInstances=function(){void 0===Er.prototype.orderFieldsObject&&(Er.prototype.orderFieldsObject={},Er.prototype.fieldSettingsForm=document.getElementById("frm-end-form-marker").closest("form"))},this.getFieldOrderInputById=function(e,t){var n,r=Er.prototype.orderFieldsObject,o=Er.prototype.fieldSettingsForm;return void 0===r[e]?(null===(n=o.querySelector('input[name="field_options[field_order_'.concat(e,']"]')))&&(n=t.querySelector('input[name="field_options[field_order_'.concat(e,']"]'))),r[e]=n,n):r[e]},this.initOnceInAllInstances(),Dn(),function(){var t,n,r,o,i,a,l=new oo,s=jQuery("li.frm_field_box",jQuery("#frm-show-fields"));for(i=0;i<s.length;i++)t=s[i].getAttribute("data-fid"),(r=null!==(n=e.getFieldOrderInputById(t,s[i]))?Object.assign({},n.value)[0]:null)!=(o=i+1)&&null!==r&&(n.value=o,a=s[i].querySelector("#frm-single-settings-".concat(t)),l.append(a),Po());l.moveFields()}()}function kr(){document.querySelectorAll(".start_divider").forEach(function(e){Ar(jQuery(e))})}function Ar(e){if(e.length){for(var t=e.find("ul.frm_sorting"),n=!1,r=t.length,o=0;o<r;++o)if(0!==ie(jQuery(t.get(o))).length){n=!0;break}e.parent().children(".frm_no_section_fields").get(0).classList.toggle("frm_block",!n)}}function Sr(){var e=jQuery(this).data("slidedown"),t=jQuery(document.getElementById(e));return t.is(":hidden")&&(t.slideDown("fast"),this.style.display="none"),!1}function Lr(){var e=jQuery(this).data("slideup"),t=jQuery(document.getElementById(e));return t.slideUp("fast"),t.siblings("a").show(),!1}function Ir(e,t){""===t.getAttribute("value")?Br(jQuery(this)):function(e){var t=e.val();if(null===t)return e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!0),void Br(e);var n=t.indexOf("");n>=0&&(t.splice(n,1),e.val(t),e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!1))}(jQuery(this))}function Br(e){e.val(""),e.next(".btn-group").find('.multiselect-container input[value!=""]').prop("checked",!1)}function qr(){jQuery(".frm-hide-empty").each(function(){0===jQuery(this).text().trim().length&&jQuery(this).remove()})}function Cr(e){e.preventDefault(),function(e,t,n){var r=document.getElementById(e.getAttribute("data-open")),o=jQuery(e).closest("p,ul"),i=void 0!==t;if(o.hasClass("frm-open"))o.removeClass("frm-open"),r.classList.add("frm_hidden");else{if(i||(t=Wo(e)),null!==t){if(!i){var a=n.key;"Enter"!==a&&" "!==a&&t.focus()}o.after(r),r.setAttribute("data-fills",t.id.replace("-proxy-input","")),0===r.id.indexOf("frm-calc-box")&&Ze(r,!0)}o.addClass("frm-open"),r.classList.remove("frm_hidden"),wp.hooks.doAction("frm_show_inline_modal",r,e)}}(this,void 0,e)}function Nr(e){e.preventDefault(),this.parentNode.classList.add("frm_hidden"),jQuery('.frm-open [data-open="'.concat(this.parentNode.id,'"]')).closest(".frm-open").removeClass("frm-open")}function Tr(e){var t=e.target;t.closest(".frm-inline-modal.frm-modal-no-dismiss")||t.closest(".frm-show-inline-modal")||t.closest("#frm_adv_info")||t.closest(".frm-token-proxy-input")||document.querySelectorAll(".frm-inline-modal.frm-modal-no-dismiss:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden"),e.previousElementSibling.classList.remove("frm-open")})}function Or(){var e,t=this.getAttribute("data-frmchange").split(",");for(e=0;e<t.length;e++)"updateOption"===t[e]?Dr(this):"updateDefault"===t[e]?Fr(this):"checkUniqueOpt"===t[e]?jr(this):this.value=this.value[t[e]]()}function Fr(e){var t=Mr(e),n=t.getAttribute("data-optkey"),r=Pr(t,n),o=t.querySelector('input[name="default_value_'.concat(r,'"]'));null!==o&&(o.value=e.value)}function Dr(e){var t,n=Mr(e),r=n.getAttribute("data-optkey"),o=Pr(n,r),i=document.getElementById("separate_value_".concat(o));null!==i&&!1===i.checked&&((t=document.getElementById("field_key_".concat(o,"-").concat(r))).value=e.value,Fr(t))}function Mr(e){var t=e.parentNode;return"LI"!==t.tagName&&(t=t.parentNode),t}function Pr(e,t){return e.id.replace("frm_delete_field_","").replace("-".concat(t,"_container"),"")}function Hr(){var e=this;if(!Ur()){$r(this);var t=jQuery(j),n=JSON.stringify(t.serializeArray());jQuery(document.getElementById("frm_compact_fields")).val(n),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_save_form",frm_compact_fields:n,nonce:frmGlobal.nonce},success:function(t){var n;(n=e).classList.remove("frm_loading_form"),n.classList.remove("frm_loading_button"),jQuery('.frm-single-settings ul input[type="text"][name^="field_options[options_"]').filter("[data-value-on-load]").removeAttr("data-value-on-load"),jQuery('input[type="hidden"][name^=optionmap]').remove(),x=0,n.setAttribute("aria-busy","false"),setTimeout(function(){jQuery(".frm_updated_message").fadeOut("slow",function(){this.remove()})},5e3);var r,o=document.getElementById("post-body-content"),i=document.createElement("div");i.setAttribute("class","frm_updated_message"),i.innerHTML=t,o.insertBefore(i,o.firstChild),(r=document.getElementById("frm_submit_side_top")).hasAttribute("data-new-addon-installed")&&"true"===r.getAttribute("data-new-addon-installed")&&(r.removeAttribute("data-new-addon-installed"),window.location.reload())},error:function(){zr(document.getElementById("frm_js_build_form"))}})}}function zr(e){var t=e.ownerDocument.createElement("input");t.style.display="none",t.type="submit",e.append(t),t.click(),t.remove()}function Rr(e){jQuery(e).trigger("change")}function Gr(){if(!Ur()){$r(this);var e=jQuery(j);jQuery(document.getElementById("frm_compact_fields")).val(JSON.stringify(e.serializeArray())),zr(document.getElementById("frm_js_build_form"))}}function Ur(){if((t=document.getElementById("frm_form_name"))&&""!==t.value.trim()||"true"!==T.get("new_template")||(null===(e=document.querySelector("#frm_top_bar #frm_bs_dropdown .frm_bstooltip"))||void 0===e?void 0:e.textContent.trim())!==frm_admin_js.noTitleText)return!1;var e,t,n=Bi("#frm-form-templates-modal","440px");return!!n&&(Uo(n,"72px"),n.dialog("open"),!0)}function Wr(){var e=document.getElementById("frm-save-form-name-button"),t=document.getElementById("frm_new_form_name_input");_(e,Vr),t.addEventListener("keydown",function(e){"Enter"===e.key&&Vr(e)})}var Vr=function(e){var t=document.getElementById("frm_new_form_name_input").value.trim(),n=new FormData;n.append("form_id",T.get("id")),n.append("form_name",t),p("rename_form",n).then(function(e){T.delete("new_template"),N.search=T.toString(),history.replaceState({},"",N.toString()),null!==document.getElementById("frm_notification_settings")&&(document.getElementById("frm_form_name").value=t,document.getElementById("frm_form_key").value=e.form_key),jQuery("#frm-publishing").find(".frm_button_submit").trigger("click")})};function $r(e){var t,n;Ci(),jQuery("form.inplace_form").length&&jQuery(".inplace_save, .postbox").trigger("click"),e.classList.contains("frm_button_submit")?e.classList.add("frm_loading_form"):e.classList.add("frm_loading_button"),e.setAttribute("aria-busy","true"),t=document.querySelectorAll(".frm_format_dropdown, .frm_phone_type_dropdown"),n={none:"",international:"international",currency:"currency",number:"number"},t.forEach(function(e){var t=e.value;t in n&&(document.getElementById("frm_format_".concat(e.dataset.fieldId)).value=n[t])})}function Kr(e){var t,n=null!==(t=e.target.dataset)&&void 0!==t&&t.modalTitle?e.target:e.target.closest("[data-modal-title]");if(n){var r=n.dataset,o=r.modalTitle,i=r.modalContent;o&&i&&(e.preventDefault(),frmDom.modal.maybeCreateModal("frmBasicModal",{title:o,content:c({className:"inside",child:d(i)})}))}}function Jr(e){var t,r,o,i=e.dataset.upgrade,a=e.getAttribute("href").replace("#",""),l=document.querySelector(".frm_".concat(a))||document.querySelector(".".concat(a));if(l&&!l.querySelector(".frm-upgrade-message")){var s=l.querySelector("h2");s.style.borderBottom="none",s.textContent=B(I("%s are not installed","formidable"),i),l.classList.add("frmcenter");var d=document.getElementById("frm_upgrade_modal");v("frm-oneclick"),v("frm-addon-status");var u=d.querySelector(".frm-upgrade-link");if(u){var f,_,p=u.closest(".frm-upgrade-modal-actions"),g=(_=p?(p=p.cloneNode(!0)).querySelector(".frm-upgrade-link"):u.cloneNode(!0)).querySelector(".license-level");g&&(g.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(e)),l.append(p||_),null!==(f=u.nextElementSibling)&&void 0!==f&&f.querySelector(".frm-link-secondary")&&l.append(u.nextElementSibling.cloneNode(!0)),v("frm-oneclick-button")}v("frm-upgrade-message");var y=e.dataset.message;void 0===y&&(y=e.dataset.upgrade),function(e,t,r){n(4260).addOneClick(e,"tab",r)}(e,0,y),e.dataset.screenshot&&l.append((t=e.dataset.screenshot,o="".concat(frmGlobal.url,"/images/screenshots/"),c({className:"frm-settings-screenshot-wrapper",children:[(r=["#ED8181","#EDE06A","#80BE30"].map(function(e){var t=c({className:"frm-minmax-icon"});return t.style.backgroundColor=e,t}),r.push(m({src:"".concat(frmGlobal.url,"/images/tab.svg")})),c({className:"frm-settings-screenshot-toolbar",children:r})),c({child:m({src:o+t})})]})))}function v(e){l.append(d.querySelector(".".concat(e)).cloneNode(!0))}}function Xr(e){void 0===e&&(e=""),function(e){var t,n=jQuery("".concat(e," :not(.frm_has_shortcodes) .frm_not_email_message, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_to, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_subject"));for(t=0;t<n.length;t++)n[t].parentNode.classList.add("frm_has_shortcodes")}(e),jQuery("".concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) input,").concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) textarea")).wrap('<span class="frm-with-right-icon"></span>').before('<svg class="frmsvg frm-show-box"><use href="#frm_more_horiz_solid_icon"/></svg>')}function Yr(){var e="success";"options[edit_action]"===this.name&&(e="edit");var t=jQuery(this).val();jQuery(".".concat(e,"_action_box")).hide(),"redirect"===t?jQuery(".".concat(e,"_action_redirect_box.").concat(e,"_action_box")).fadeIn("slow"):"page"===t?jQuery(".".concat(e,"_action_page_box.").concat(e,"_action_box")).fadeIn("slow"):jQuery(".".concat(e,"_action_message_box.").concat(e,"_action_box")).fadeIn("slow")}function Zr(e){if(!function(e){var t=jQuery(e),n=t.closest(".frm_form_action_settings"),r=n.find(".widget-inside");if(r.find("p, div, table").length)return!1;var o=n.find(".widget-top");return o.on("frm-action-loaded",function(){t.trigger("click"),n.removeClass("open"),r.hide()}),o.trigger("click"),!0}(e.target)){var t=e.target.closest(".frm_form_action_settings"),n=t.querySelectorAll(".wp-editor-area");n.length&&n.forEach(function(e){tinymce.EditorManager.execCommand("mceRemoveEditor",!0,e.id)});var r=jQuery(t).clone(),o=r.attr("id").replace("frm_form_action_",""),i=eo(o);r.find(".frm_action_id, .frm-btn-group").remove(),r.find('input[name$="['.concat(o,'][ID]"]')).val(""),r.find(".widget-inside").hide(),r.find("input[type=text], textarea, input[type=number]").prop("defaultValue",function(){return this.value}),r.find("input[type=checkbox], input[type=radio]").prop("defaultChecked",function(){return this.checked});var a=new RegExp("\\[".concat(o,"\\]"),"g"),l=new RegExp("_".concat(o,'"'),"g"),s=new RegExp("-".concat(o,'"'),"g"),d=new RegExp('"'.concat(o,'"'),"g"),u=r.html().replace(a,"[".concat(i,"]")).replace(l,"_".concat(i,'"'));u=u.replace(s,"-".concat(i,'"')).replace(d,'"'.concat(i,'"'));var f=c({id:"frm_form_action_".concat(i),className:r.get(0).className});f.setAttribute("data-actionkey",i),f.innerHTML=u,f.querySelectorAll(".wp-editor-wrap, .wp-editor-wrap *").forEach(function(e){"string"==typeof e.className&&(e.className=e.className.replace(o,i)),e.id=e.id.replace(o,i)}),f.classList.remove("open"),document.getElementById("frm_notification_settings").append(f),n.length&&(n.forEach(function(e){frmDom.wysiwyg.init(e)}),f.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e)})),f.classList.contains("frm_single_on_submit_settings")&&f.querySelector("input.frm-page-search")&&yi(f),ci(),wp.hooks.doAction("frm_after_duplicate_action",f)}}function eo(e){var t=parseInt(e,10)+11;return null!==document.getElementById("frm_form_action_".concat(t))&&(t=eo(++t)),t}function to(){var e,t=jQuery(this).data("actiontype");if(!co(t)){var n=(e=Ln(document.querySelectorAll(".frm_form_action_settings"),"frm_form_action_"),void 0!==document.getElementById("frm_form_action_".concat(e))&&(e+=100),S>=e&&(e=S+1),S=e,e),r=E,o=document.createElement("div");o.classList.add("frm_single_".concat(t,"_settings"));var i=document.getElementById("frm_notification_settings");i.append(o),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_action",type:t,list_id:n,form_id:r,nonce:frmGlobal.nonce},success:function(e){Po(),o.remove(),document.querySelectorAll(".frm_form_action_settings.open").forEach(function(e){return e.classList.remove("open")});var r=c();r.innerHTML=e;var a=r.querySelector(".widget-top");Array.from(r.children).forEach(function(e){return i.append(e)}),jQuery(".frm_form_action_settings").fadeIn("slow");var l=document.getElementById("frm_form_action_".concat(n));l.classList.add("open"),document.getElementById("post-body-content").scroll({top:l.offsetTop+10,left:0,behavior:"smooth"}),so(t),Xr("#frm_form_action_".concat(n)),ci(),yi(l),a&&jQuery(a).trigger("frm-action-loaded"),frmAdminBuild.hooks.doAction("frm_added_form_action",l)}})}}function no(){var e=document.getElementById("frm_email_addon_menu").classList,t=document.getElementById("actions-search-input");e.contains("frm-all-actions")?(e.remove("frm-all-actions"),e.add("frm-limited-actions")):(e.add("frm-all-actions"),e.remove("frm-limited-actions")),t.value="",ki(t,"input")}function ro(e){e.on("Change",function(){!function(e){(function(){var e=document.querySelector(".frm-single-settings:not(.frm_hidden)");if(!e)return!1;var t=e.querySelector(".wp-editor-wrap");return null!==t&&t.classList.contains("tmce-active")})()&&!tinyMCE.activeEditor.isHidden()&&(e.targetElm.value=e.getContent(),jQuery(e.targetElm).trigger("change"))}(e)})}function oo(e){var t=this;if(null!==e)return this.fragment=document.createDocumentFragment(),this.initOnceInAllInstances=function(){void 0===oo.prototype.endMarker&&(oo.prototype.endMarker=document.getElementById("frm-end-form-marker"))},this.append=function(e){var n=null!==e?e.parentElement.classList:"";null!==e&&(n.contains("frm_field_box")||n.contains("divider_section_only"))&&t.fragment.append(e)},this.moveFields=function(){j.insertBefore(t.fragment,oo.prototype.endMarker)},this.initOnceInAllInstances(),void 0!==e?(this.append(e),void this.moveFields()):{append:this.append,moveFields:this.moveFields}}function io(){var e=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),t=this.getAttribute("data-emailrow");jQuery("#frm_form_action_".concat(e," .frm_").concat(t,"_row")).fadeIn("slow"),jQuery(this).fadeOut("slow")}function ao(){var e=jQuery(this).closest(".frm_form_action_settings"),t=this.getAttribute("data-emailrow"),n=".frm_".concat(t,"_row"),r=".frm_".concat(t,"_button");jQuery(e).find(r).fadeIn("slow"),jQuery(e).find(n).fadeOut("slow",function(){jQuery(e).find("".concat(n," input")).val("")})}function lo(){var e=jQuery(this).closest(".frm_form_action_settings"),t=".frm_from_to_match_row";e.find('input[name$="[post_content][from]"]').val()===e.find('input[name$="[post_content][email_to]"]').val()?jQuery(e).find(t).fadeIn("slow"):jQuery(e).find(t).fadeOut("slow")}function so(e){var t,n,r=document.querySelectorAll(".frm_".concat(e,"_action"));co(e)?(t=r,n=uo(e)>0,t.forEach(function(e){e.classList.remove("frm_active_action"),e.classList.add("frm_inactive_action"),n&&e.classList.add("frm_already_used")})):r.forEach(function(e){e.querySelector(".frm_show_upgrade")||(e.classList.remove("frm_inactive_action","frm_already_used"),e.classList.add("frm_active_action"))})}function co(e){var t=function(e){return jQuery(".frm_single_".concat(e,"_settings")).length}(e)>=uo(e),n={type:e};return wp.hooks.applyFilters("frm_action_at_limit",t,n)}function uo(e){return parseInt(jQuery(".frm_".concat(e,"_action")).data("limit"),10)}function fo(){var e=i.only_one_action,t=this.dataset.limit;void 0!==t&&((t=parseInt(t))>1?e=e.replace(1,t).trim():e+=" ".concat(i.edit_action_text)),M(e)}function mo(){var e=jQuery(this).data("emailkey"),t=jQuery(this).closest(".frm_form_action_settings").find(".frm_action_name").val(),n=document.getElementById("form_id").value,r=document.getElementById("frm_logic_row_".concat(e)),o=Ln(r.querySelectorAll(".frm_logic_row"),"frm_logic_".concat(e,"_")),i=c({id:"frm_logic_".concat(e,"_").concat(o),className:"frm_logic_row frm_hidden"});return r.append(i),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_logic_row",email_id:e,form_id:n,meta_name:o,type:t,nonce:frmGlobal.nonce},success:function(t){jQuery(document.getElementById("logic_link_".concat(e))).fadeOut("slow",function(){i.insertAdjacentHTML("beforebegin",t),i.remove(),jQuery(r).parent(".frm_logic_rows").fadeIn("slow")})}}),!1}function _o(){var e=jQuery("select.frm_single_post_field");e.css("border-color","");var t=this,n=jQuery(t).val();if(""===n||"checkbox"===n)return!1;e.each(function(){if(jQuery(this).val()===n&&this.name!==t.name)return this.style.borderColor="red",jQuery(t).val(""),M(i.field_already_used),!1})}function po(){var e=jQuery(this).val();""===e?(jQuery(".frm_post_content_opt, select.frm_dyncontent_opt").hide().val(""),jQuery(".frm_dyncontent_opt").hide()):"post_content"===e?(jQuery(".frm_post_content_opt").show(),jQuery(".frm_dyncontent_opt").hide(),jQuery("select.frm_dyncontent_opt").val("")):(jQuery(".frm_post_content_opt").hide().val(""),jQuery("select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt").show())}function go(){var e=jQuery(this).val(),t=jQuery(document.getElementById("frm_dyncontent"));""===e||"new"===e?(t.val(""),jQuery(".frm_dyncontent_opt").show()):jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_display_get_content",id:e,nonce:frmGlobal.nonce},success:function(e){t.val(e),jQuery(".frm_dyncontent_opt").show()}})}function yo(){var e,t,n=document.getElementById("frm_posttax_rows").childNodes,r=document.querySelector(".frm_post_parent_field"),o=document.querySelector(".frm_post_menu_order_field"),i=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_replace_posttax_options",post_type:i,nonce:frmGlobal.nonce},success:function(r){for(var o=0;o<n.length;o++)"DIV"===n[o].tagName&&(e=n[o].getElementsByTagName("select")[0],(t=document.createElement("select")).innerHTML=r,t.className=e.className,t.name=e.name,n[o].replaceChild(t,e))}}),r&&vo(r,i,"frm_get_post_parent_option",function(e,t){r.querySelector(".frm_post_parent_opt_wrapper").innerHTML=e.replaceAll("REPLACETHISNAME",t),yi(r)}),o&&vo(o,i,"frm_should_use_post_menu_order_option")}function vo(e,t,n,r){var o=(e.querySelector(".frm_autocomplete_value_input")||e.querySelector("select")).getAttribute("name");jQuery.ajax({url:ajaxurl,method:"POST",data:{action:n,post_type:t,_wpnonce:frmGlobal.nonce},success:function(t){if("string"==typeof t){if("0"===t)return e.classList.add("frm_hidden"),void(e.value="");e.classList.remove("frm_hidden"),"function"==typeof r&&r(t,o)}else console.error(t)},error:function(e){return console.error(e)}})}function ho(){jo("tax",this)}function bo(){jo("meta",this)}function jo(e,t){var n,r,o=jQuery('input[name="id"]').val(),i=jQuery(t).closest(".frm_form_action_settings"),a=i.data("actionkey"),l=i.find(".frm_post_type").val(),s=0,c=document.querySelectorAll(".frm_post".concat(e,"_row"));c.length&&(r=n=c[c.length-1].id.replace("frm_post".concat(e,"_"),""),s=!isNaN(parseFloat(r))&&isFinite(r)?1+parseInt(n,10):1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_post".concat(e,"_row"),form_id:o,meta_name:s,tax_key:s,post_type:l,action_key:a,nonce:frmGlobal.nonce},success:function(t){var n,r;if(jQuery(document.getElementById("frm_post".concat(e,"_rows"))).append(t),jQuery(".frm_add_post".concat(e,"_row.button")).hide(),"meta"===e)for(jQuery(".frm_name_value").show(),n=document.querySelectorAll(".frm_toggle_cf_opts"),r=0;r<n.length-1;++r)n[r].style.display="none";else"tax"===e&&jQuery(".frm_posttax_labels").show()}})}function wo(){if(jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").length){jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").html('<div class="spinner frm_spinner" style="display:block"></div>');var e=jQuery(this).closest(".frm_form_action_settings").find('select[name$="[post_content][post_type]"]').val(),t=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),n=jQuery(this).closest(".frm_posttax_row").attr("id").replace("frm_posttax_",""),r=jQuery(this).val(),o=jQuery(document.getElementById("".concat(n,"_show_exclude"))).is(":checked")?1:0,i=jQuery('select[name$="[post_category]['.concat(n,'][field_id]"]')).val(),a=jQuery('input[name="id"]').val();jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_posttax_row",form_id:a,post_type:e,tax_key:n,action_key:t,meta_name:r,field_id:i,show_exclude:o,nonce:frmGlobal.nonce},success:function(e){jQuery(document.getElementById("frm_posttax_".concat(n))).replaceWith(e)}})}}function Qo(){var e=jQuery(this).closest(".frm_postmeta_row"),t=e.find(".frm_cancelnew"),n=e.find(".frm_enternew");return e.find("select.frm_cancelnew").is(":visible")?(t.hide(),n.show()):(t.show(),n.hide()),e.find("input.frm_enternew, select.frm_cancelnew").val(""),!1}function xo(){var e=jQuery(this),t=e.val();"checkbox"===e.attr("type")&&!1===this.checked&&(t="");var n=e.data("toggleclass");""===t?jQuery(".".concat(n)).hide():(jQuery(".".concat(n)).show(),jQuery(".hide_".concat(n,"_").concat(t)).hide())}function Eo(){Ur()||($r(this),zr(document.querySelector(".frm_form_settings")))}function ko(e){return e.preventDefault(),Ao(jQuery(this),this.getAttribute("data-code")),!1}function Ao(e,t){var n=!1,r=e;if("object"===a(e)){if(e.hasClass("frm_noallow"))return;void 0===(r=jQuery(e).closest("[data-fills]").attr("data-fills"))&&void 0!==(r=e.closest("div").attr("class"))&&(r=r.split(" ")[1])}if(void 0===r){var o=document.activeElement;"search"===o.type?null===(r=o.id.replace("-search-input","")).match(/\d/gi)&&(r=(o=jQuery(".frm-single-settings:visible .".concat(r))).attr("id")):r=o.id}r&&(n=jQuery("#wp-".concat(r,"-wrap.wp-editor-wrap")).length>0);var i=jQuery(document.getElementById(r));if(void 0===e.attr("data-shortcode")&&(!i.length||void 0===i.attr("data-shortcode"))){var l=e.parents("ul.frm_code_list").attr("data-shortcode");"undefined"!==l&&"no"===l||(t="[".concat(t,"]"))}if(n&&(wpActiveEditor=r),!i.length)return!1;if("[default-html]"===t||"[default-plain]"===t){var s=0;"[default-plain]"===t&&(s=1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_default_html",form_id:jQuery('input[name="id"]').val(),plain_text:s,nonce:frmGlobal.nonce},elementId:r,success:function(e){if(n){var t=document.createElement("p");t.innerText=e,send_to_editor(t.innerHTML)}else So(i,e)}})}else t=function(e,t,n){return"object"===a(t)&&t instanceof jQuery&&0===n[0].id.indexOf("success_url_")&&(t=t[0]).closest("#frm-insert-fields-box")?(t.parentNode.classList.contains("frm_insert_url")||(e=e.replace("]"," sanitize_url=1]")),e):e}(t,e,i),n?send_to_editor(t):So(i,t);return!1}function So(e,t){if(document.selection)e[0].focus(),document.selection.createRange().text=t;else{var n=e[0],r=n.selectionEnd;t=function(e,t,n,r){var o=e.data("sep");if(void 0===o)return t;var i=e.val();if(!i.trim().length)return t;var a=new RegExp("".concat(o,"\\s*$")),l=new RegExp("^\\s*".concat(o));return i.substr(0,n).trim().length&&!1===a.test(i.substr(0,n))&&(t=o+t),i.substr(r,i.length).trim().length&&!1===l.test(i.substr(r,i.length))&&(t+=o),t}(e,t,n.selectionStart,r),n.value=n.value.substr(0,n.selectionStart)+t+n.value.substr(n.selectionEnd,n.value.length);var o=r+t.length;!function(e,t){if(e.classList.contains("frm_classes")&&Lo(t)){var n=e.value.split(" ").filter(Lo);n.length&&(e.value=function(e,t,n){var r=e.split(" ").filter(function(e){return(e=e.trim()).length&&!t.includes(e)});return r.includes(n)||r.push(n),r.join(" ")}(e.value,n,t.trim()))}}(n,t),n.focus(),n.setSelectionRange(o,o)}Rr(e)}function Lo(e){return["frm_half","frm_third","frm_two_thirds","frm_fourth","frm_three_fourths","frm_fifth","frm_sixth","frm2","frm3","frm4","frm6","frm8","frm9","frm10","frm12"].includes(e.trim())}function Io(){var e=document.getElementById("frm-id-condition"),t=document.getElementById("frm-key-condition");"id"===this.value?(e.classList.remove("frm_hidden"),t.classList.add("frm_hidden"),ki(t,"change")):(e.classList.add("frm_hidden"),t.classList.remove("frm_hidden"),ki(e,"change"))}function Bo(){var e=document.getElementById("frm-id-key-condition-id").checked?"frm-id-condition":"frm-key-condition",t=document.getElementById("frm-is-condition").value,n=document.getElementById("frm-text-condition").value,r=document.getElementById("frm-insert-condition"),o=(e=document.getElementById(e)).options[e.selectedIndex].value,a="if ".concat(o," ").concat(t,'="').concat(n,'"]');r.setAttribute("data-code","".concat(a+i.conditional_text,"[/if ").concat(o)),r.innerHTML="[".concat(a,"[/if ").concat(o,"]")}function qo(e){return e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href")}function Co(e){var t;e.parentNode.parentNode.classList.contains("frm_has_shortcodes")&&($o(),"use"===(t=Vo(e)).tagName?qo(t=t.firstElementChild).includes("frm_close_icon")||Do(t,"nofocus"):t.classList.contains("frm_close_icon")||Do(t,"nofocus"))}function No(e){e.preventDefault(),e.stopPropagation(),Do(this)}function To(e){!function(e){var t;if(e.id.startsWith("field_options_type_")){var n=e.id.split("_"),r=n.length&&n[n.length-1];null!==(t=document.querySelector("#frm-single-settings-".concat(r)))&&void 0!==t&&t.classList.contains("frm-type-".concat(e.value))||Oo()}}(e.target)}function Oo(e){var t;void 0===e&&(e=I("You are changing the field type. Not all field settings will appear as expected until you reload the page. Would you like to reload the page now?","formidable")),frmDom.modal.maybeCreateModal("frmSaveAndReloadModal",{title:I("Save and Reload?","formidable"),content:(t=c(e),t.style.padding="var(--gap-md)",t),footer:function(){var e=frmDom.modal.footerButton({text:I("Save and Reload","formidable"),buttonType:"primary"});_(e,function(){var e;(e=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&e.setAttribute("data-new-addon-installed",!0),e.click()});var t=frmDom.modal.footerButton({text:I("Cancel","formidable"),buttonType:"cancel"});return t.classList.add("dismiss"),frmDom.div({children:[t,e]})}()})}function Fo(e){var t;if(e instanceof Event){var n=document.querySelectorAll(".frm-single-settings .frm-show-box.frmsvg use"),r=Array.from(n).find(function(e){return"#frm_close_icon"===e.getAttribute("href")});if(void 0===r)return;t=r.parentElement}else t=e;var o=t.getBoundingClientRect(),i=document.getElementById("frm_adv_info"),a=i.parentElement.getBoundingClientRect();i.style.top="".concat(o.top-a.top+32,"px"),i.style.left="".concat(o.left-a.left-280,"px")}function Do(e,t){var n=Wo(e),r=document.getElementById("frm_adv_info"),a=e.className;if("svg"===e.tagName&&(e=e.firstElementChild),"use"===e.tagName&&(a=qo(e)),a.includes("frm_close_icon"))$o(r);else{if(Fo(e),jQuery(".frm_code_list a").removeClass("frm_noallow"),n.classList.contains("frm_not_email_to")?jQuery("#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a").addClass("frm_noallow"):n.classList.contains("frm_not_email_subject")&&jQuery(".frm_code_list li.hide_frm_not_email_subject a").addClass("frm_noallow"),r.setAttribute("data-fills",n.id),r.style.display="block","use"===e.tagName)if(e.hasAttributeNS("http://www.w3.org/1999/xlink","href"))e.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon");else{var l=document.createElementNS("http://www.w3.org/2000/svg","use");l.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon"),e.parentNode.replaceChild(l,e)}else e.className=a.replace("frm_more_horiz_solid_icon","frm_close_icon");"nofocus"!==t&&("none"!==n.style.display?n.focus():jQuery(tinymce.get(n.id)).trigger("focus")),function(e){["address","body"].forEach(function(t){!function(e,t){var n,r=i.contextualShortcodes["".concat(t,"Selector")],a=i.contextualShortcodes[t],l=e.matches(r),s=function(e){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=o(e))){t&&(e=t);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==t.return||t.return()}finally{if(l)throw i}}}}(a);try{for(s.s();!(n=s.n()).done;){var c,d=n.value,u=null===(c=document.querySelector('#frm-adv-info-tab .frm_code_list [data-code="'.concat(d,'"]')))||void 0===c?void 0:c.closest("li");null==u||u.classList.toggle("frm_hidden",!l)}}catch(e){s.e(e)}finally{s.f()}}(e,t)})}(n)}}function Mo(e){return 0===i.contextualShortcodes.length||!function(e){var t=e.querySelector("a");if(!t)return!1;var n=t.dataset.code;return i.contextualShortcodes.address.includes(n)||i.contextualShortcodes.body.includes(n)}(e)||function(e){var t=e.querySelector("a").dataset.code,n=document.getElementById("frm_adv_info").dataset.fills,r=document.getElementById(n),o=i.contextualShortcodes;return o.address.includes(t)?r.matches(o.addressSelector):r.matches(o.bodySelector)}(e)}function Po(){x||(x=1,window.addEventListener("beforeunload",Go))}function Ho(){x=0}function zo(){x=0}function Ro(){x=0}function Go(e){x&&(e.preventDefault(),e.returnValue="")}function Uo(e,t){var n={my:"top",at:"top+".concat(t),of:window};e.dialog("option","position",n)}function Wo(e){if(e.classList.contains("frm-input-icon"))return e.previousElementSibling;for(var t,n=e.nextElementSibling;null!==n&&("INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName||n.classList.contains("frm-token-input-field"));)n=Wo(n);return n||(n=null===(t=e.closest(".frm-field-formula"))||void 0===t?void 0:t.querySelector(".frm-calc-field")),n}function Vo(e){var t;if(null!==(t=e.nextElementSibling)&&void 0!==t&&t.classList.contains("frm-input-icon"))return e.nextElementSibling;for(var n=e.previousElementSibling;null!==n&&"I"!==n.tagName&&"svg"!==n.tagName;)n=Vo(n);return n}function $o(e){if((void 0!==e||null!==(e=document.getElementById("frm_adv_info")))&&null===document.getElementById("frm_dyncontent")){e.style.display="none";for(var t=document.querySelectorAll(".frm-show-box.frm_close_icon"),n=0;n<t.length;n++)t[n].classList.remove("frm_close_icon"),t[n].classList.add("frm_more_horiz_solid_icon");for(var r=document.querySelectorAll(".frm_has_shortcodes use"),o=0;o<r.length;o++)if("#frm_close_icon"===qo(r[o])){if(r[o].closest(".frm_remove_field"))continue;r[o].setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_more_horiz_solid_icon")}}}function Ko(e,t){t.stopPropagation(),jQuery(".frm_code_list .frmids, .frm_code_list .frmkeys").addClass("frm_hidden"),jQuery(".frm_code_list .".concat(e)).removeClass("frm_hidden"),jQuery(".frmids, .frmkeys").removeClass("current"),jQuery(".".concat(e)).addClass("current")}function Jo(e){var t=e.target.closest(".frm_form_action_settings");t&&(t.classList.contains("frm_single_email_settings")||t.classList.contains("frm_single_on_submit_settings"))&&function(e){e.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e,{height:160,addFocusEvents:!0})})}(t)}function Xo(){return!0===D(this)&&(jQuery(".frm_uninstall .frm-wait").css("visibility","visible"),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_uninstall&nonce=".concat(frmGlobal.nonce),success:function(e){jQuery(".frm_uninstall").fadeOut("slow"),window.location=e}})),!1}function Yo(){var e=jQuery(this),t=this.name,n=this.getAttribute("data-plugin"),r=t.replace("edd_".concat(n,"_license_"),""),o=document.getElementById("edd_".concat(n,"_license_key")).value;e.get(0).disabled=!0,jQuery.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_".concat(r),license:o,plugin:n,nonce:frmGlobal.nonce},success:function(t){e.get(0).disabled=!1;var i=e.closest(".edd_frm_license_row");"deactivate"===r&&(o="",document.getElementById("edd_".concat(n,"_license_key")).value=""),i.find(".edd_frm_license").html(o);var a=e.get(0).closest(".frm_form_field"),l=!0===t.success;a.querySelector(".frm_icon_font.frm_action_success").classList.toggle("frm_hidden",!l||"deactivate"===r),a.querySelector(".frm_icon_font.frm_action_error").classList.toggle("frm_hidden",l);var s=i.find(".frm_license_msg");s.html(t.message),""!==t.message&&setTimeout(function(){if(s.html(""),i.find(".frm_icon_font").addClass("frm_hidden"),l){var e="activate"===r;i.get(0).querySelector(".edd_frm_unauthorized").classList.toggle("frm_hidden",e),i.get(0).querySelector(".edd_frm_authorized").classList.toggle("frm_hidden",!e)}},2e3)}})}function Zo(e){e.preventDefault();var t=jQuery(e.target).find("input:checked");if(t.length){var n,r,o,i,a=[];t.each(function(e){a[e]=this.value}),n=a,r=e.target,(i=(o=jQuery(r)).next(".frm-importer-process")).find(".form-total").text(n.length),i.find(".form-current").text("1"),o.hide(),i.find(".process-completed").hide(),i.show(),C.importQueue=n,C.imported=0,ei(i)}}function ei(e){var t=C.importQueue[0],n=jQuery("#welcome-panel").find('input[name="slug"]').val(),r={action:"frm_import_".concat(n),form_id:t,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,r,function(n){var r;n.success&&(r=n.data.error?"<p>".concat(n.data.name,": ").concat(n.data.msg,"</p>"):'<p>Imported <a href="'.concat(n.data.link,'" target="_blank">').concat(n.data.name,"</a></p>"),e.find(".status").prepend(r),e.find(".status").show(),C.importQueue=jQuery.grep(C.importQueue,function(e){return e!=t}),C.imported++,0===C.importQueue.length?(e.find(".process-count").hide(),e.find(".forms-completed").text(C.imported),e.find(".process-completed").show()):(e.find(".form-current").text(C.imported+1),ei(e)))})}function ti(e){e.preventDefault();var t=!1,n=jQuery('input[name="frm_export_forms[]"]');jQuery('input[name="frm_export_forms[]"]:checked').val()||(n.closest(".frm-table-box").addClass("frm_blank_field"),t="stop");var r=jQuery('input[name="type[]"]');if(jQuery('input[name="type[]"]:checked').val()||"checkbox"!==r.attr("type")||(r.closest("p").addClass("frm_blank_field"),t="stop"),"stop"===t)return!1;e.stopPropagation(),this.submit()}function ni(){var e=jQuery(this).closest(".frm_blank_field");if(void 0!==e){var t=this.name;("type[]"===t&&jQuery('input[name="type[]"]:checked').val()||"frm_export_forms[]"===t&&jQuery(this).val())&&e.removeClass("frm_blank_field")}}function ri(){null!==jQuery(this).val().match(/\.csv$/i)?jQuery(".show_csv").fadeIn():jQuery(".show_csv").fadeOut()}function oi(){var e=document.querySelector('select[name="format"]');return e?e.value:""}function ii(e){var t,n,r=e.target.value;li(r),ai.call(e.target),t=r,n=document.getElementById("frm-export-select-all"),"csv"===t?(n.checked=!1,n.disabled=!0):n.disabled=!1}function ai(){var e=jQuery(this),t=e.find(":selected"),n=t.data("support"),r=n.indexOf("|");jQuery('input[name="type[]"]').each(function(){this.checked=!1,n.includes(this.value)?(this.disabled=!1,-1===r&&(this.checked=!0)):this.disabled=!0}),"csv"===e.val()?(jQuery(".csv_opts").show(),jQuery(".xml_opts").hide()):(jQuery(".csv_opts").hide(),jQuery(".xml_opts").show());var o=t.data("count"),i=jQuery('input[name="frm_export_forms[]"]');"single"===o?(i.prop("multiple",!1),i.prop("checked",!1)):(i.prop("multiple",!0),i.prop("disabled",!1)),e.trigger("change")}function li(e){if(""!==e){var t=document.querySelectorAll(".frm-is-repeater");t.length&&("csv"===e?t.forEach(function(e){e.classList.remove("frm_hidden")}):t.forEach(function(e){e.classList.add("frm_hidden")}),Qi.call(document.querySelector(".frm-auto-search")))}}function si(){var e=jQuery("select[name=format]").find(":selected").data("count"),t=jQuery('input[name="frm_export_forms[]"]');"single"===e&&this.checked?(t.prop("disabled",!0),this.removeAttribute("disabled")):t.prop("disabled",!1)}function ci(){jQuery(".frm_multiselect").hide().each(frmDom.bootstrap.multiselect.init)}function di(e){e.preventDefault(),mi(this,"frm_multiple_addons")}function ui(e){e.preventDefault(),mi(this,"frm_activate_addon")}function fi(e){e.preventDefault(),mi(this,"frm_install_addon")}function mi(e,t){n(1105).toggleAddonState(e,t)}function _i(){gi()}function pi(e){!function(e,t,n){var r=jQuery("#frm_leave_email_error");r.removeClass("frm_hidden").attr("frm-error",n),jQuery("#frm_leave_email").one("keyup",function(){r.addClass("frm_hidden")})}(0,0,e)}function gi(){var e=document.getElementById("frmapi-email-form");jQuery.ajax({dataType:"json",url:e.getAttribute("data-url"),success:function(t){var n=t.renderedHtml;n=n.replace(/<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi,""),e.innerHTML=n}})}function yi(e){frmDom.autocomplete.initSelectionAutocomplete(e)}function vi(e){var t=this.parentNode.parentNode,n=t.elements.type.value;e.preventDefault(),this.classList.add("frm_loading_button"),bi(t,n,this)}function hi(e){var t=this.elements.type.value,n=this.querySelector("button");e.preventDefault(),n.classList.add("frm_loading_button"),bi(this,t,n)}function bi(e,t,n){var r=function(e){var t,n,r={},o=e.elements;for(n=0;n<o.length;n++){var i=o[n],a=i.name,l=i.value,s=a.match(/(.*)\[(.*)\]/);("radio"!==i.type&&"checkbox"!==i.type||i.checked)&&(null===s?Reflect.has(r,a)?(Array.isArray(r[a])||(r[a]=[r[a]]),r[a].push(l)):r[a]=l:(a=s[1],t=s[2],Reflect.has(r,a)||(r[a]={}),r[a][t]=l))}return r}(e),o=r.template_name,i=r.template_desc,a=e.elements.link.value,l={action:t,xml:a,name:o,desc:i,form:JSON.stringify(r),nonce:frmGlobal.nonce},s={formData:r};Ai(l=wp.hooks.applyFilters("frm_before_install_new_form",l,s),function(t){if(void 0!==t.redirect){var r=t.redirect;if(void 0===e.elements.redirect)window.location=r;else{var o=document.getElementById("frm-redirect-link");void 0!==a&&null!==o&&(o.setAttribute("href",r),o.classList.remove("frm_grey","disabled"),(i=e.parentNode.parentNode).classList.add("frm_grey"),i.nextElementSibling.classList.remove("frm_grey"),n.classList.add("frm_grey","disabled"))}}else jQuery(".spinner").css("visibility","hidden"),"string"==typeof t.message&&function(e){var t=c(e);t.style.padding="20px 40px",frmDom.modal.maybeCreateModal("frmInstallFormErrorModal",{title:I("Unable to install template","formidable"),content:t}).classList.add("frm_common_modal")}(t.message);var i;n.classList.remove("frm_loading_button")})}function ji(e){var t=document.getElementById("frm_captcha_threshold_container");t&&t.classList.toggle("frm_hidden","v3"!==e.target.value)}function wi(e){var t=this.getAttribute("data-id");e.preventDefault(),Ai({action:"frm_forms_trash",id:t,nonce:frmGlobal.nonce},function(){var e=document.getElementById("frm-template-custom-".concat(t));Si(e,function(){e.remove()})})}function Qi(){var e,t,n=!1,r=this.value.toLowerCase(),o=this.getAttribute("data-tosearch"),i=document.getElementsByClassName(o);if("SELECT"===this.tagName&&(r=function(e){for(var t,n=[],r=null==e?void 0:e.options,o=0,i=null==r?void 0:r.length;o<i;o++)(t=r[o]).selected&&n.push(t.value);return n}(this),r=r.join("|").toLowerCase(),n=!0),"frm-action"===o&&""!==r){var a=document.getElementById("frm_email_addon_menu").classList;a.remove("frm-all-actions"),a.add("frm-limited-actions")}for(e=0;e<i.length;e++){var l=i[e].innerText.toLowerCase(),s=!("xml"===oi()&&i[e].classList.contains("frm-is-repeater"));""===r?(s&&Mo(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.remove("frm-search-result")):n&&new RegExp(r).test(l)||l.includes(r)||xi(l,r)?(s&&Mo(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.add("frm-search-result")):(i[e].classList.add("frm_hidden"),i[e].classList.remove("frm-search-result"))}(t=document.querySelector("#frm-insert-fields"))&&t.querySelectorAll(":scope > .frm-with-line").forEach(function(e){var t=e.nextElementSibling;if(t){var n=t.querySelectorAll(":scope > li.frmbutton"),r=Array.from(n).every(function(e){return e.classList.contains("frm_hidden")});e.classList.toggle("frm_hidden",r)}}),jQuery(this).trigger("frmAfterSearch")}function xi(e,t){return"s"!==t&&"s"!==e[e.length-1]&&"".concat(e,"s").includes(t)}function Ei(e){e.stopPropagation()}function ki(e,t){var n=document.createEvent("HTMLEvents");n.initEvent(t,!1,!0),e.dispatchEvent(n)}function Ai(e,t){var n,r=new XMLHttpRequest,o="string"==typeof e?e:Object.keys(e).map(function(t){return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e[t]))}).join("&");return r.open("post",ajaxurl,!0),r.onreadystatechange=function(){if(r.readyState>3&&200==r.status){n=r.responseText;try{n=JSON.parse(n)}catch(e){}t(n)}},r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.send(o),r}function Si(e,t){e.classList.add("frm-fade"),setTimeout(t,1e3)}function Li(e){jQuery(e).css("visibility","hidden")}function Ii(e){jQuery(e).css("visibility","visible")}function Bi(e,t){return n(4260).initModal(e,t)}function qi(e,t){if("#"===t){var n=document.getElementById(e),r=n.style.display;n.style.display="none"===r?"block":"none"}else e.is(":visible")?e.hide():e.show()}function Ci(){window.onbeforeunload=null;var e=jQuery(window);e.off("beforeunload.widgets"),e.off("beforeunload.edit-post")}function Ni(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));if(null!==t&&"form"===t.dataset.type)if(t=jQuery(t),this.options[this.selectedIndex].value){t.find(".frm-not-set")[0].classList.add("frm_hidden");var n=t.find(".frm-embed-message");n.html(n.data("embedmsg")+this.options[this.selectedIndex].text),t.find(".frm-embed-field-placeholder")[0].classList.remove("frm_hidden")}else t.find(".frm-not-set")[0].classList.remove("frm_hidden"),t.find(".frm-embed-field-placeholder")[0].classList.add("frm_hidden")}function Ti(){var e=jQuery(this).closest(".frm-single-settings"),t=e.find(".frmjs_product_choices"),n=e.find(".frm_prod_options_heading"),r=this.options[this.selectedIndex].value;t.removeClass("frm_prod_type_single frm_prod_type_user_def"),n.removeClass("frm_prod_user_def"),"single"===r?t.addClass("frm_prod_type_single"):"user_def"===r&&(t.addClass("frm_prod_type_user_def"),n.addClass("frm_prod_user_def"))}function Oi(e){var t=document.getElementById("frm_field_id_".concat(e));return null!==t&&"product"===t.getAttribute("data-type")}function Fi(){var e=function(e,t){return window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]},t=function(e,t,n){window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]=n},n=[1,2,3,4,5,6,7,8,9,10,11,12].map(function(e){return"frm".concat(e)}),o=["first","middle","last"];document.addEventListener("change",function(i){i.target.matches(".frm_name_layout_dropdown")&&function(i){var a,l=i.target.value.split("_"),s=i.target.dataset.fieldId,c=document.querySelector("#field_".concat(s,"_inner_container .frm_combo_inputs_container")),d=(a=l.length,"frm".concat(parseInt(12/a)));o.forEach(function(e){var o,i=c.querySelector('[data-sub-field-name="'.concat(e,'"]'));i&&(i.classList.add("frm_hidden"),(o=i.classList).remove.apply(o,r(n)),t(s,e,i))}),l.forEach(function(t){var n=e(s,t);n&&(n.classList.remove("frm_hidden"),n.classList.add(d),c.append(n))}),o.forEach(function(e){var n=document.querySelector(".frm_sub_field_options-".concat(e,'[data-field-id="').concat(s,'"]'));n&&(n.classList.add("frm_hidden"),t(s,"".concat(e,"_options"),n))}),l.forEach(function(t){var n=e(s,"".concat(t,"_options"));n&&n.classList.remove("frm_hidden")})}(i)},!1)}function Di(e,t){var n,r,o,i=!1,a=!1;(n=t.newOption?(new DOMParser).parseFromString(t.newOption,"text/html").body.childNodes[0]:t).querySelectorAll("svg").forEach(function(e){(r=e.getElementsByTagNameNS("http://www.w3.org/2000/svg","use")[0])&&("#frm_drag_icon"===(o=qo(r))&&(i=!0),"#frm_save_icon"===o&&(a=!0))}),i||n.prepend(h.drag.cloneNode(!0)),n.querySelector("[id^=field_key_".concat(e,"-]"))&&!a&&n.querySelector("[id^=field_key_".concat(e,"-]")).after(h.save.cloneNode(!0)),t.newOption&&(t.newOption=n)}function Mi(){var e=document.getElementById("frm_leave_email").value.trim();if(""!==e)if(!1!==/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test(e)){var t=jQuery("#frmapi-email-form").find("form"),n=t.find('[type="email"]').not(".frm_verify");if(n.length){if(document.getElementById("frm_empty_inbox")){document.getElementById("frm-add-my-email-address").remove();var r=document.getElementById("frm_leave_email_wrapper");if(r){r.classList.add("frm_hidden");var o=d({className:"frm-wait frm_spinner"});o.style.visibility="visible",o.style.float="none",o.style.width="unset",r.parentElement.insertBefore(o,r.nextElementSibling)}}n.val(e),jQuery.ajax({type:"POST",url:t.attr("action"),data:"".concat(t.serialize(),"&action=frm_forms_preview")}).done(function(e){if(jQuery(e).find(".frm_message").text().trim().includes("Thanks!")){var t=document.getElementById("frmapi-email-form").parentElement.querySelector(".frm_spinner");t&&t.remove(),wp.hooks.applyFilters("frm_thank_you_on_signup",!0)&&document.getElementById("frm_leave_email_wrapper").replaceWith(d(I("Thank you for signing up!","formidable")))}else pi("invalid")})}}else pi("invalid");else pi("empty")}function Pi(e){var t;if(O||e.stopPropagation(),!(e.target.classList.contains("frm-show-box")||null!==(t=e.target.parentElement)&&void 0!==t&&t.classList.contains("frm-show-box"))){var n=document.getElementById("frm_adv_info");n&&(n.dataset.fills===e.target.id&&void 0!==e.target.id||e.target.closest("#frm_adv_info")||"none"===n.style.display||$o(n))}}return{init:function(){var e,t,o,i,a,l,s;!function(){jQuery(document).on("click","#frm-add-my-email-address",function(e){e.preventDefault(),Mi()});var e=document.getElementById("frm_empty_inbox"),t=document.getElementById("frm_leave_email");if(e&&t){var n=document.getElementById("frm-leave-email-modal");n.classList.remove("frm_hidden"),n.querySelector(".frm_modal_footer").classList.add("frm_hidden"),t.addEventListener("keyup",function(e){if("Enter"===e.key){var t=document.getElementById("frm-add-my-email-address");t&&t.click()}})}}(),t=document.querySelector(".frm-admin-footer-links"),o=null!==(e=document.querySelector(".frm_page_container"))&&void 0!==e?e:document.getElementById("wpbody-content"),t&&o&&(o.append(t),t.classList.remove("frm_hidden")),document.addEventListener("show.bs.dropdown",function(){z()}),C={},jQuery(".wp-admin").on("click",function(e){var t=jQuery(e.target),n=jQuery(".dropdown.open");!n.length||t.hasClass("dropdown")||t.closest(".dropdown").length||n.removeClass("open")}),jQuery("#frm_bs_dropdown:not(.open) a").on("click",At),void 0===E&&(E=jQuery(document.getElementById("form_id")).val()),document.querySelectorAll(".frm-warning-dismiss").forEach(function(e){_(e,St)}),frmAdminBuild.inboxBannerInit(),b.length>0?frmAdminBuild.buildInit():null!==document.getElementById("frm_notification_settings")?frmAdminBuild.settingsInit():null!==document.getElementById("frm_styling_form")?frmAdminBuild.styleInit():null!==document.getElementById("form_global_settings")?frmAdminBuild.globalSettingsInit():null!==document.getElementById("frm_export_xml")?frmAdminBuild.exportInit():null!==document.querySelector(".frm-inbox-wrapper")?frmAdminBuild.inboxInit():null!==document.getElementById("frm-welcome")?frmAdminBuild.solutionInit():(function(){if(document.body.classList.contains("frm-admin-page-entries")){var e=document.getElementById("screen-options-wrap");if(e){var t=c({className:"frm_warning_style",text:I("Only 10 columns can be selected at a time.","formidable")});t.style.margin=0;var n=e.querySelector("legend");n.parentNode.insertBefore(t,n.nextElementSibling);var r=Array.from(e.querySelectorAll('input[type="checkbox"]')),o=function(){r.reduce(function(e,t){return t.checked?e+1:e},0)>=10?(t.classList.remove("frm_hidden"),r.forEach(function(e){e.checked||(e.parentNode.classList.add("frm_noallow"),e.disabled=!0)})):t.classList.add("frm_hidden")};o(),r.forEach(function(e){e.addEventListener("change",function(e){e.target.checked?o():(t.classList.add("frm_hidden"),r.forEach(function(e){e.parentNode.classList.remove("frm_noallow"),e.disabled=!1}))})})}}}(),yi(),jQuery("[data-frmprint]").on("click",function(){return window.print(),!1})),jQuery(document).on("change","select[data-toggleclass], input[data-toggleclass]",xo),function(){function e(e){var t=e.options[e.selectedIndex];e.querySelectorAll("option[data-dependency]:not([data-dependency-skip])").forEach(function(e){var n=document.querySelector(e.dataset.dependency);null==n||n.classList.toggle("frm_hidden",t!==e)})}document.querySelectorAll("select.frm_select_with_dependency").forEach(e),frmDom.util.documentOn("change","select.frm_select_with_dependency",function(t){return e(t.target)})}(),(jQuery(document.getElementById("frm_adv_info")).length>0||jQuery(".frm_field_list").length>0)&&frmAdminBuild.panelInit(),i=jQuery(".wrap, .frm_wrap"),a=document.getElementById("frm_confirm_modal"),l=!1,s=!1,jQuery(a).on("click","[data-deletefield]",xn),jQuery(a).on("click","[data-removeid]",R),jQuery(a).on("click","[data-trashtemplate]",wi),i.on("click",".frm_remove_tag, .frm_remove_form_action",R),i.on("click","a[data-frmverify]",F),i.on("click","a[data-frmtoggle]",P),i.on("click","a[data-frmhide], a[data-frmshow]",H),i.on("change","input[data-frmhide], input[data-frmshow]",H),i.on("click",".widget-top,a.widget-action",G),i.on("mouseenter.frm",".frm_bstooltip, .frm_help",function(){jQuery(this).off("mouseenter.frm"),function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=e;(n.hasAttribute("data-toggle")||n.hasAttribute("data-bs-toggle"))&&(n.parentElement.setAttribute("title",n.getAttribute("title")),n.removeAttribute("title"),n.classList.remove("frm_bstooltip"),n.parentElement.classList.add("frm_bstooltip"),n=n.parentElement),jQuery(n).tooltip(),t&&(z(),jQuery(n).tooltip("show"))}(this,!0)}),jQuery(document).on("click","#doaction, #doaction2",function(e){var t="doaction"===this.id?"top":"bottom",n=document.getElementById("bulk-action-selector-".concat(t)),r=document.getElementById("confirm-bulk-delete-".concat(t));if(null!==n&&null!==r){if(l=this,!s&&"bulk_delete"===n.value)return e.preventDefault(),D(r),!1}else l=!1}),jQuery(document).on("click","#frm-confirmed-click",function(e){if(!1!==l&&!e.target.classList.contains("frm-btn-inactive"))return"confirm-bulk-delete"===this.getAttribute("href")?(e.preventDefault(),s=!0,l.click(),!1):void 0}),n(4260).initUpgradeModal(),frmDom.util.documentOn("click","[data-modal-title]",Kr);var d=jQuery(document.getElementById("frm_shortcodediv"));d.length>0&&(jQuery("a.edit-frm_shortcode").on("click",function(){return d.is(":hidden")&&(d.slideDown("fast"),this.style.display="none"),!1}),jQuery(".cancel-frm_shortcode","#frm_shortcodediv").on("click",function(){return d.slideUp("fast"),d.siblings("a.edit-frm_shortcode").show(),!1})),jQuery(document).on("click","#frm-nav-tabs a",U),jQuery(".post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a").on("click",function(){var e=this.classList.contains("frm_show_upgrade_tab");if(!this.classList.contains("frm_noallow")||e)return e&&Jr(this),W(this),!1}),W(jQuery(".starttab a"),"auto"),jQuery(document).on("click","#frm-fid-search-menu a",function(){var e=this.id.replace("fid-","");return jQuery('select[name="fid"]').val(e),zr(document.getElementById("posts-filter")),!1}),jQuery(".frm_select_box").on("click focus",function(){this.select()}),jQuery(document).on("input search change",".frm-auto-search:not(#frm-form-templates-page #template-search-input)",Qi),jQuery(document).on("focusin click",".frm-auto-search",Ei);var u=jQuery(".frm-auto-search");""!==u.val()&&u.trigger("keyup"),FrmFormsConnect.init(),jQuery(document).on("click",".frm-install-addon",fi),jQuery(document).on("click",".frm-activate-addon",ui),jQuery(document).on("click",".frm-solution-multiple",di),jQuery("button, input[type=submit]").on("click",Ci),document.addEventListener("click",function(e){if("LABEL"===e.target.nodeName){var t=e.target.getAttribute("for");if(t){var n=document.getElementById(t);if(n&&n.nextElementSibling){var r=n.nextElementSibling.querySelector("button.dropdown-toggle.multiselect");r&&setTimeout(function(){return r.click()},0)}}}}),frmAdminBuild.hooks.addFilter("frm_before_embed_modal",function(e,t){var n,r,o=t.element;if("form"!==t.type)return e;var i=o.closest("tr");if(i)n=parseInt(i.querySelector(".column-id").textContent),r=i.querySelector(".column-form_key").textContent;else{n=document.getElementById("form_id").value;var a=document.getElementById("frm_form_key");if(a)r=a.value;else{var l=document.getElementById("frm-previewDrop");l&&(r=l.nextElementSibling.querySelector(".dropdown-item a").getAttribute("href").split("form=")[1])}}return[n,r]}),document.querySelectorAll("#frm-show-fields > li, .frm_grid_container li").forEach(function(e,t){e.addEventListener("click",function(){var e,t,n;t=(null===(e=this.querySelector("li"))||void 0===e?void 0:e.dataset.fid)||this.dataset.fid,(n=document.querySelectorAll("[id^=frm_delete_field_".concat(t,"-]"))).length<2||r(n).slice(1).forEach(function(e,n){e.classList.contains("frm_other_option")||Di(t,e)})})});var f=document.getElementById("frm_small_screen_proceed_button");f&&_(f,function(){var e;null===(e=document.getElementById("frm_small_device_message_container"))||void 0===e||e.remove(),p("small_screen_proceed",new FormData)});var m=document.getElementById("frm_sale_banner"),g=null==m?void 0:m.querySelector(".dismiss");m&&(_(m,function(e){e.target.closest(".dismiss")||(window.location.href=m.getAttribute("data-url"))}),g&&_(g,function(){m.remove();var e=new FormData;p("sale_banner_dismiss",e)}))},buildInit:function(){jQuery("#frm_builder_page").on("mouseup","*:not(.frm-show-box)",Pi),g=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return frmDom.util.debounce(e,t)}(oe,10),y=document.getElementById("post-body-content"),v=jQuery(y),jQuery(".frm_field_loading").length&&Ee(jQuery(".frm_field_loading").first().attr("id")),V("ul.frm_sorting"),document.querySelectorAll(".field_type_list > li:not(.frm_show_upgrade):not(.frm_show_update)").forEach(X),jQuery("ul.field_type_list, .field_type_list li, ul.frm_code_list, .frm_code_list li, .frm_code_list li a, #frm_adv_info #category-tabs li, #frm_adv_info #category-tabs li a").disableSelection(),jQuery(".frm_submit_ajax").on("click",Hr),jQuery(".frm_submit_no_ajax").on("click",Gr),Wr(),jQuery("a.edit-form-status").on("click",Sr),jQuery(".cancel-form-status").on("click",Lr),jQuery(".save-form-status").on("click",function(){var e=jQuery(document.getElementById("form_change_status")).val();return jQuery('input[name="new_status"]').val(e),jQuery(document.getElementById("form-status-display")).html(e),jQuery(".cancel-form-status").trigger("click"),!1}),jQuery(".frm_form_builder form").first().on("submit",function(){jQuery(".inplace_field").trigger("blur")}),ci(),Dn();var e,t=jQuery(j),n=document.getElementById("frm_form_editor_container");t.on("click",".frm_add_logic_row",Sn),t.on("click",".frm_add_watch_lookup_row",In),t.on("change",".frm_get_values_form",On),t.on("change",".frm_logic_field_opts",wr),t.on("frm-multiselect-changed",'select[name^="field_options[admin_only_"]',Ir),jQuery(document.getElementById("frm-insert-fields")).on("click",".frm_add_field",Ae),b.on("click",".frm_clone_field",Be),t.on("blur",'input[id^="frm_calc"]',Je),t.on("change","input.frm_format_opt, input.frm_max_length_opt",lt),t.on("change click","[data-changeme]",it),t.on("click","input.frm_req_field",st),t.on("click",".frm_mark_unique",dt),t.on("change",".frm_repeat_format",Xn),t.on("change",".frm_repeat_limit",Yn),t.on("change",".frm_js_checkbox_limit",Zn),t.on("input",'input[name^="field_options[add_label_"]',function(){er(this,"add")}),t.on("input",'input[name^="field_options[remove_label_"]',function(){er(this,"remove")}),t.on("change",'select[name^="field_options[data_type_"]',Fn),jQuery(n).on("click",".frm-collapse-page",Mn),jQuery(n).on("click",".frm-collapse-section",zn),t.on("click",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",Rn),t.on("keydown",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),Rn.call(this,e))}),jQuery(n).on("show.bs.dropdown hide.bs.dropdown",He),t.on("click",".frm_toggle_sep_values",yt),t.on("click",".frm_toggle_image_options",vt),t.on("click",".frm_remove_image_option",Et),t.on("click",".frm_choose_image_box",xt),t.on("change",".frm_hide_image_text",Qt),t.on("change",".frm_field_options_image_size",jt),t.on("click",".frm_multiselect_opt",kt),b.on("mousedown","input, textarea, select",Lt),b.on("click","input[type=radio], input[type=checkbox]",Lt),b.on("click",".frm_delete_field",Nt),b.on("click",".frm_select_field",Tt),jQuery(document).on("click",".frm_delete_field_group",Ot),jQuery(document).on("click",".frm_clone_field_group",Ft),jQuery(document).on("click","#frm_field_group_controls > span:first-child",Dt),jQuery(document).on("click",".frm-row-layout-option",Yt),jQuery(document).on("click",".frm-merge-fields-into-row .frm-row-layout-option",Zt),jQuery(document).on("click",".frm-custom-field-group-layout",tn),jQuery(document).on("click",".frm-merge-fields-into-row .frm-custom-field-group-layout",rn),jQuery(document).on("click",".frm-break-field-group",cn),b.on("click","#frm_field_group_popup .frm_grid_container input",dn),jQuery(document).on("click",".frm-cancel-custom-field-group-layout",un),jQuery(document).on("click",".frm-save-custom-field-group-layout",mn),b.on("click","ul.frm_sorting",_n),jQuery(document).on("click",".frm-merge-fields-into-row",jn),jQuery(document).on("click",".frm-delete-field-groups",Qn),b.on("click",'.frm-field-action-icons [data-toggle="dropdown"]',function(){this.closest("li.form-field").classList.add("frm-field-settings-open"),jQuery(document).on("click","#frm_builder_page",Te)}),b.on("mousemove","ul.frm_sorting",Oe),b.on("show.bs.dropdown",".frm-field-action-icons",Me),jQuery(document).on("show.bs.dropdown","#frm_field_group_controls",Pe),t.on("click",".frm_single_option a[data-removeid]",It),t.on("mousedown",".frm_single_option input[type=radio]",Bt),t.on("focusin",".frm_single_option input[type=text]",qt),t.on("click",".frm_add_opt",_t),t.on("change",".frm_single_option input",nr),t.on("change",".frm_image_id",nr),t.on("change",".frm_toggle_mult_sel",pt),b.on("click",".frm_primary_label",Un),b.on("click",".frm_description",Wn),b.on("click","li.ui-state-default:not(.frm_noallow)",$n),b.on("dblclick","li.ui-state-default",Jn),t.on("change",".frm_tax_form_select",tr),t.on("change","select.conf_field",ut),t.on("change",".frm_get_field_selection",Qr),t.on("click",".frm-show-inline-modal",Cr),t.on("keydown",".frm-show-inline-modal",function(e){var t=e.key;"Enter"!==t&&" "!==t||(e.preventDefault(),Cr.call(this,e))}),t.on("click",".frm-inline-modal .dismiss",Nr),jQuery(document).on("change","[data-frmchange]",Or),document.addEventListener("click",Tr),t.on("change",".frm_include_extras_field",et),t.on("change",'select[name^="field_options[form_select_"]',Ni),jQuery(document).on("submit","#frm_js_build_form",Ho),jQuery(document).on("change","#frm_builder_page input:not(.frm-search-input):not(.frm-custom-grid-size-input), #frm_builder_page select, #frm_builder_page textarea",Po),rt(),jQuery(document).on("change",".frmjs_prod_data_type_opt",Ti),jQuery(document).on("focus",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',qn),jQuery(document).on("blur",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Nn),frmDom.util.documentOn("click",".frm-show-field-settings",$n),frmDom.util.documentOn("change","select.frm_format_dropdown, select.frm_phone_type_dropdown",Kn),t.on("keydown",'.frm_single_option input[name^="field_options["], .frm_single_option input[name^="rows_"]',function(e){"Enter"===e.key&&function(e){var t=e.closest(".frm_single_option").parentElement.querySelectorAll('.frm_single_option input[name^="field_options[" ], .frm_single_option input[name^="rows_"]'),n=Array.from(t),r=n.indexOf(e);if(!(r<0)){var o=n.slice(r+1).find(function(e){return null!==e.offsetParent});if(o){o.focus();var i=o.value.length;o.setSelectionRange(i,i)}}}(e.currentTarget)}),!1!==(e=Bi("#frm-bulk-modal","700px"))&&(jQuery(".frm-insert-preset").on("click",mt),jQuery(j).on("click","a.frm-bulk-edit-link",function(t){t.preventDefault();var n="",r=jQuery(this).closest("[data-fid]").data("fid"),o=yr(r),i=Oi(r),a=document.getElementById("frm_field_".concat(r,"_opts"));if(a){var l=a.getElementsByTagName("li");document.getElementById("bulk-field-id").value=r;for(var s=0;s<l.length;s++){var c=l[s].getAttribute("data-optkey");if("000"!==c){var d=document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][label]"))[0];void 0!==d&&(n+=d.value,o&&(n+="|".concat(document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][value]"))[0].value)),i&&(n+="|".concat(document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][price]"))[0].value)),n+="\r\n")}s>=l.length-1&&(document.getElementById("frm_bulk_options").value=n)}return e.dialog("open"),!1}}),jQuery("#frm-update-bulk-opts").on("click",function(){var t=document.getElementById("bulk-field-id").value;document.getElementById("bulk-option-type").value||(this.classList.add("frm_loading_button"),frmAdminBuild.updateOpts(t,document.getElementById("frm_bulk_options").value,e),Po())})),qr(),document.addEventListener("frm_added_field",qr),Ie(),Fi(),kr(),frmDom.util.documentOn("change",".frm_show_password_setting_input",function(e){var t=e.target.getAttribute("data-fid"),n=document.getElementById("frm_field_id_".concat(t));n&&n.classList.toggle("frm_disabled_show_password",!e.target.checked)}),document.addEventListener("scroll",Fo,!0),document.addEventListener("change",To),document.querySelector(".frm_form_builder").addEventListener("mousedown",function(e){e.shiftKey&&e.preventDefault()}),wp.hooks.addAction("frmShowedFieldSettings","formidableAdmin",function(e,t){t.querySelectorAll(".frm-collapse-me").forEach(Gn)},9999)},settingsInit:function(){var e=jQuery(document.getElementById("frm_notification_settings"));e.on("click",".frm_email_buttons",io),e.on("click",".frm_remove_field",ao),e.on("change",".frm_to_row, .frm_from_row",lo),e.on("change",".frm_tax_selector",wo),e.on("change","select.frm_single_post_field",_o),e.on("change","select.frm_toggle_post_content",po),e.on("change","select.frm_dyncontent_opt",go),e.on("change",".frm_post_type",yo),e.on("click",".frm_add_postmeta_row",bo),e.on("click",".frm_add_posttax_row",ho),e.on("click",".frm_toggle_cf_opts",Qo),e.on("click",".frm_duplicate_form_action",Zr),jQuery(".frm_actions_list").on("click",".frm_active_action",to),jQuery("#frm-show-groups, #frm-hide-groups").on("click",no),ci(),jQuery("ul.frm_actions_list li").each(function(){so(jQuery(this).children("a").data("actiontype"));var e=jQuery(this).find("i");"none"!==e.css("background-image")&&e.addClass("frm-inverse")}),jQuery(".frm_submit_settings_btn").on("click",Eo),Wr();var t=jQuery(".frm_form_settings");t.on("click",".frm_add_form_logic",mo),t.on("click",".frm_already_used",fo),document.addEventListener("click",function(e){var t=e.target;t.closest(".frm_image_preview_wrapper")&&(t.closest(".frm_choose_image_box")?xt.bind(t)(e):t.closest(".frm_remove_image_option")&&Et.bind(t)(e))}),t.on("mouseup","*:not(.frm-show-box)",Pi),jQuery(document.getElementById("no_save")).on("change",function(){this.checked&&!0!==confirm(i.no_save_warning)&&jQuery(this).attr("checked",!1)}),jQuery('select[name="options[edit_action]"]').on("change",Yr);var n=document.getElementById("logged_in");jQuery(n).on("change",function(){this.checked?Ii(".hide_logged_in"):Li(".hide_logged_in")});var r=jQuery(document.getElementById("frm_cookie_expiration"));jQuery(document.getElementById("frm_single_entry_type")).on("change",function(){"cookie"===this.value?r.fadeIn("slow"):r.fadeOut("slow")});var o=document.getElementById("single_entry");jQuery(o).on("change",function(){this.checked?Ii(".hide_single_entry"):Li(".hide_single_entry"),this.checked&&"cookie"===jQuery(document.getElementById("frm_single_entry_type")).val()?r.fadeIn("slow"):r.fadeOut("slow")}),jQuery(".hide_save_draft").hide();var a=jQuery(document.getElementById("save_draft"));a.on("change",function(){this.checked?jQuery(".hide_save_draft").fadeIn("slow"):jQuery(".hide_save_draft").fadeOut("slow")}),Rr(a);var l=document.getElementById("editable");jQuery(l).on("change",function(){this.checked?(jQuery(".hide_editable").fadeIn("slow"),Rr(document.getElementById("edit_action"))):(jQuery(".hide_editable").fadeOut("slow"),jQuery(".edit_action_message_box").fadeOut("slow"))}),jQuery(document).on("change","#protect_files",function(){this.checked?jQuery(".hide_protect_files").fadeIn("slow"):jQuery(".hide_protect_files").fadeOut("slow")}),jQuery(document).on("frm-multiselect-changed","#protect_files_role",Ir),jQuery(document).on("submit",".frm_form_settings",zo),jQuery(document).on("change","#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea",Po),yi(),jQuery(document).on("frm-action-loaded",Jo),frmDom.util.documentOn("change",'.frm_on_submit_type input[type="radio"]',function(e){if(e.target.checked){var t=e.target.closest(".frm_form_action_settings");t.querySelectorAll(".frm_on_submit_dependent_setting:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden")}),t.querySelectorAll(".frm_on_submit_dependent_setting[data-show-if-".concat(e.target.value,"]")).forEach(function(e){e.classList.remove("frm_hidden")}),t.setAttribute("data-on-submit-type",e.target.value)}}),wp.hooks.addAction("frm_reset_fields_updated","formidableAdmin",Ro)},panelInit:function(){jQuery(".frm_wrap, #postbox-container-1").on("click",".frm_insert_code",ko),jQuery(document).on("change",".frm_insert_val",function(){Ao(jQuery(this).data("target"),jQuery(this).val()),jQuery(this).val("")}),jQuery(document).on("click change",'[name="frm-id-key-condition"]',Io),jQuery(document).on("keyup change",".frm-build-logic",Bo),Xr(),jQuery(document).on("frmElementAdded",function(e,t){Xr(t)}),jQuery(document).on("mousedown",".frm-show-box",No);var e=document.getElementById("form_settings_page"),t=document.body.classList.contains("post-type-frm_display"),n=document.getElementById("frm_insert_fields_tab");(null!==e||t||O)&&jQuery(document).on("focusin","form input, form textarea",function(r){var o,i,a;if(r.stopPropagation(),Co(this),jQuery(this).is(":not(:submit, input[type=button], .frm-search-input, input[type=checkbox])")){if(jQuery(r.target).closest("#frm_adv_info").length)return;if(null!==e||O)o=jQuery("#frm_html_tab"),jQuery(this).closest("#html_settings").length>0?(o.show(),o.siblings().hide(),jQuery("#frm_html_tab a").trigger("click"),void 0===(a=this.id)||a.includes("-search-input")||(jQuery("#frm-adv-info-tab").attr("data-fills",a.trim()),this.classList.contains("field_custom_html")&&(a="field_custom_html"),jQuery.inArray(a,["after_html","before_html","submit_html","field_custom_html"])>=0&&(jQuery(".frm_code_list li:not(.show_".concat(a,")")).addClass("frm_hidden"),jQuery(".frm_code_list li.show_".concat(a)).removeClass("frm_hidden")))):((i=jQuery(".frm-category-tabs li"))[0]&&(i[0].style.display=""),n.click(),o.hide(),o.siblings().show());else if(t){var l=new CustomEvent("frm_legacy_views_handle_field_focus");l.frmData={idAttrValue:this.id},document.dispatchEvent(l)}}}),jQuery(".frm_wrap, #postbox-container-1").on("mousedown","#frm_adv_info a, .frm_field_list a",function(e){e.preventDefault()});var r=jQuery("#frm_adv_info");r.on("click",".subsubsub a.frmids",function(e){Ko("frmids",e)}),r.on("click",".subsubsub a.frmkeys",function(e){Ko("frmkeys",e)})},inboxInit:function(){var e;jQuery(".frm_inbox_dismiss").on("click",function(e){var t=this.parentNode.parentNode,n=t.getAttribute("data-message"),r=this.getAttribute("href"),o=t.cloneNode(!0),i=document.querySelector(".frm-dismissed-inbox-messages");if("free_templates"!==n||this.classList.contains("frm_inbox_dismiss")){e.preventDefault();var a={action:"frm_inbox_dismiss",key:n,nonce:frmGlobal.nonce},l="frm_inbox_slide_in"===t.id;l&&(t.classList.remove("s11-fadein"),t.classList.add("s11-fadeout"),t.addEventListener("animationend",function(){return t.remove()},{once:!0})),Ai(a,function(){if(!l)return"#"!==r?(window.location=r,!0):void Si(t,function(){var e;null!==i&&(o.classList.remove("frm-fade"),null===(e=o.querySelector(".frm-inbox-message-heading .frm_inbox_dismiss"))||void 0===e||e.remove(),i.append(o)),1===t.parentNode.querySelectorAll(".frm-inbox-message-container").length&&(document.getElementById("frm_empty_inbox").classList.remove("frm_hidden"),t.parentNode.closest(".frm-active").classList.add("frm-empty-inbox"),_i()),t.remove()})})}}),!1===(null===(e=document.getElementById("frm_empty_inbox"))||void 0===e?void 0:e.classList.contains("frm_hidden"))&&_i()},solutionInit:function(){jQuery(document).on("submit","#frm-new-template",hi)},styleInit:function(){var e=jQuery(".frm_image_preview_wrapper");e.on("click",".frm_choose_image_box",xt),e.on("click",".frm_remove_image_option",Et),wp.hooks.doAction("frm_style_editor_init")},customCSSInit:function(){console.warn("Calling frmAdminBuild.customCSSInit is deprecated.")},globalSettingsInit:function(){jQuery(document).on("click","[data-frmuninstall]",Xo),ci();var e=document.getElementById("licenses_settings");null!==e&&jQuery(e).on("click",".edd_frm_save_license",Yo),jQuery(document).on("click","#frm-new-template button",vi),jQuery("#frm-dismissable-cta .dismiss").on("click",function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"frm_lite_settings_upgrade",nonce:frmGlobal.nonce}),jQuery(".settings-lite-cta").remove()});var t=document.getElementById("frm_re_type");t&&t.addEventListener("change",ji),document.querySelector(".frm_captchas").addEventListener("change",function(e){var t,n=null===(t=document.querySelector('.frm_captchas input[checked="checked"]'))||void 0===t?void 0:t.value,r=e.target.value!==n;document.querySelector(".captcha_settings .frm_note_style").classList.toggle("frm_hidden",!r)}),frmDom.util.documentOn("submit",".frm_settings_form",function(){x=0});var n=document.getElementById("manage_styles_settings");n&&n.addEventListener("change",function(e){var t=e.target;"SELECT"===t.nodeName&&t.dataset.name&&!t.getAttribute("name")&&t.setAttribute("name",t.dataset.name)});var r=document.getElementById("payments_settings"),o=null==r?void 0:r.querySelectorAll('[name="frm_payment_section"]');o&&o.forEach(function(e){e.addEventListener("change",function(){if(e.checked){var t=r.querySelector('label[for="'.concat(e.id,'"]'));t&&t.setAttribute("aria-selected","true"),o.forEach(function(t){if(t!==e){var n=r.querySelector('label[for="'.concat(t.id,'"]'));n&&n.setAttribute("aria-selected","false")}})}})})},exportInit:function(){jQuery(".frm_form_importer").on("submit",Zo),jQuery(document.getElementById("frm_export_xml")).on("submit",ti),jQuery("#frm_export_xml input, #frm_export_xml select").on("change",ni),jQuery('input[name="frm_import_file"]').on("change",ri),document.querySelector('select[name="format"]').addEventListener("change",ii),jQuery('input[name="frm_export_forms[]"]').on("click",si),ci(),jQuery(".frm-feature-banner .dismiss").on("click",function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"frm_dismiss_migrator",plugin:this.id,nonce:frmGlobal.nonce}),this.parentElement.remove()}),li(oi()),document.querySelector("#frm-export-select-all").addEventListener("change",function(e){document.querySelectorAll('[name="frm_export_forms[]"]').forEach(function(t){t.checked=e.target.checked})})},inboxBannerInit:function(){var e=document.getElementById("frm_banner");if(e){var t=e.querySelector(".frm-banner-dismiss");document.addEventListener("click",function(n){n.target===t&&Ai({action:"frm_inbox_dismiss",key:e.dataset.key,nonce:frmGlobal.nonce},function(){jQuery(e).fadeOut(400,function(){e.remove()})})})}},updateOpts:function(e,t,n){var r=yr(e),o=Oi(e)?"frm_bulk_products":"frm_import_options";jQuery.ajax({type:"POST",url:ajaxurl,data:{action:o,field_id:e,opts:t,separate:r,nonce:frmGlobal.nonce},success:function(t){document.getElementById("frm_field_".concat(e,"_opts")).innerHTML=t,wp.hooks.doAction("frm_after_bulk_edit_opts",e),ir(e),void 0!==n&&(n.dialog("close"),document.getElementById("frm-update-bulk-opts").classList.remove("frm_loading_button"))}})},triggerRemoveLogic:function(e,t){jQuery("#frm_logic_".concat(e,"_").concat(t," .frm_remove_tag")).trigger("click")},downloadXML:function(e,t,n){var r="".concat(ajaxurl,"?action=frm_").concat(e,"_xml&ids=").concat(t);null!==n&&(r="".concat(r,"&is_template=").concat(n)),location.href=r},hooks:{applyFilters:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return(t=wp.hooks).applyFilters.apply(t,[e].concat(r))},addFilter:function(e,t,n){return wp.hooks.addFilter(e,"formidable",t,n)},doAction:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return(t=wp.hooks).doAction.apply(t,[e].concat(r))},addAction:function(e,t,n){return wp.hooks.addAction(e,"formidable",t,n)}},applyZebraStriping:function(e,t){var n=document.querySelectorAll("".concat(e," tr").concat(t?":not(.".concat(t,")"):""));if(!(n.length<1)){var r=!0;n.forEach(function(e){e.classList.remove("frm-odd","frm-even"),e.classList.add(r?"frm-odd":"frm-even"),r=!r}),document.querySelectorAll(e).forEach(function(e){return e.classList.add("frm-zebra-striping")})}},initModal:Bi,infoModal:M,offsetModalY:Uo,adjustConditionalLogicOptionOrders:lr,addRadioCheckboxOpt:cr,installNewForm:bi,toggleAddonState:mi,purifyHtml:_r,loadApiEmailForm:gi,addMyEmailAddress:Mi,fillDropdownOpts:dr,showSaveAndReloadModal:Oo,clearSettingsBox:$e,deleteField:kn,insertFormField:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(n){var r=E,o=0;"summary"===e&&(o=b.children('li[data-type="break"]').length>0?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Object.assign(_e(e,0,r,o),{field_options:t}),success:function(t){n(t),setTimeout(function(){Er(),We(t,!0);var n=ye(t);n&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:n,fieldType:e,form_id:r})},10)},error:he})})},confirmLinkClick:D,handleInsertFieldByDraggingResponse:ge,handleAddFieldClickResponse:Le,syncLayoutClasses:ae,moveFieldSettings:oo,maybeCollapseSettings:Rn}},window.frmAdminBuild=frmAdminBuildJS(),jQuery(document).ready(function(){var e;frmAdminBuild.init(),document.querySelectorAll(".frm-dropdown-menu").forEach(function(e){e.classList.add("dropdown-menu");var t,n,r=e.querySelector(".frm-dropdown-toggle");r&&(r.hasAttribute("role")||r.setAttribute("role","button"),r.hasAttribute("tabindex")||r.setAttribute("tabindex",0)),"UL"===e.tagName&&(n=(n=(n=(n=(n=(n=(t=e).outerHTML).replace("<ul ","<div ")).replace("</ul>","</div>")).replaceAll("<li>",'<div class="dropdown-item">')).replaceAll('<li class="','<div class="dropdown-item ')).replaceAll("</li>","</div>"),t.outerHTML=n)}),null===(e=document.querySelector(".preview.dropdown .frm-dropdown-toggle"))||void 0===e||e.setAttribute("data-bs-toggle","dropdown"),document.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))})}),window.frm_show_div=function(e,t,n,r){t==n?jQuery(r+e).fadeIn("slow").css("visibility","visible"):jQuery(r+e).fadeOut("slow")},window.frmCheckAll=function(e,t){jQuery('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmCheckAllLevel=function(e,t,n){jQuery(".frm_catlevel_".concat(n)).children(".frm_checkbox").children("label").children('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmGetFieldValues=function(e,t,n,r,o,i){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_get_field_values¤t_field=".concat(t,"&field_id=").concat(e,"&name=").concat(o,"&t=").concat(r,"&form_action=").concat(jQuery('input[name="frm_action"]').val(),"&nonce=").concat(frmGlobal.nonce),success:function(e){document.getElementById("frm_show_selected_values_".concat(t,"_").concat(n)).innerHTML=e,"function"==typeof i&&i()}})},window.frmImportCsv=function(e){var t="";"undefined"!=typeof __FRMURLVARS&&(t=__FRMURLVARS),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_import_csv&nonce=".concat(frmGlobal.nonce,"&frm_skip_cookie=1").concat(t),success:function(t){var n=jQuery(".frm_admin_progress_bar").attr("aria-valuemax"),r=n-t,o=r/n*100;jQuery(".frm_admin_progress_bar").css("width","".concat(o,"%")).attr("aria-valuenow",r),parseInt(t,10)>0?(jQuery(".frm_csv_remaining").html(t),frmImportCsv(e)):(jQuery(document.getElementById("frm_import_message")).html(frm_admin_js.import_complete),setTimeout(function(){location.href="?page=formidable-entries&frm_action=list&form=".concat(e,"&import-message=1")},2e3))}})}})(); | |
| 1 | +/* exported frm_add_logic_row, frm_remove_tag, frm_show_div, frmCheckAll, frmCheckAllLevel */ | |
| 2 | + | |
| 3 | +var frmAdminBuild; | |
| 4 | + | |
| 5 | +var FrmFormsConnect = window.FrmFormsConnect || ( function( document, window, $ ) { | |
| 6 | + | |
| 7 | + /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl */ | |
| 8 | + | |
| 9 | + var el = { | |
| 10 | + licenseBox: document.getElementById( 'frm_license_top' ), | |
| 11 | + messageBox: document.getElementsByClassName( 'frm_pro_license_msg' )[0], | |
| 12 | + btn: document.getElementById( 'frm-settings-connect-btn' ), | |
| 13 | + reset: document.getElementById( 'frm_reconnect_link' ) | |
| 14 | + }; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Public functions and properties. | |
| 18 | + * | |
| 19 | + * @since 4.03 | |
| 20 | + * | |
| 21 | + * @type {Object} | |
| 22 | + */ | |
| 23 | + var app = { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * Register connect button event. | |
| 27 | + * | |
| 28 | + * @since 4.03 | |
| 29 | + */ | |
| 30 | + init: function() { | |
| 31 | + $( document.getElementById( 'frm_deauthorize_link' ) ).on( 'click', app.deauthorize ); | |
| 32 | + $( '.frm_authorize_link' ).on( 'click', app.authorize ); | |
| 33 | + if ( el.reset !== null ) { | |
| 34 | + $( el.reset ).on( 'click', app.reauthorize ); | |
| 35 | + } | |
| 36 | + | |
| 37 | + $( el.btn ).on( 'click', function( e ) { | |
| 38 | + e.preventDefault(); | |
| 39 | + app.gotoUpgradeUrl(); | |
| 40 | + }); | |
| 41 | + | |
| 42 | + window.addEventListener( 'message', function( msg ) { | |
| 43 | + if ( msg.origin.replace( /\/$/, '' ) !== frmGlobal.app_url.replace( /\/$/, '' ) ) { | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + | |
| 47 | + if ( ! msg.data || 'object' !== typeof msg.data ) { | |
| 48 | + console.error( 'Messages from "' + frmGlobal.app_url + '" must contain an api key string.' ); | |
| 49 | + return; | |
| 50 | + } | |
| 51 | + | |
| 52 | + app.updateForm( msg.data ); | |
| 53 | + }); | |
| 54 | + | |
| 55 | + jQuery( document ).on( 'mouseover', '#frm_new_form_modal .frm-selectable', function() { | |
| 56 | + var $item = jQuery( this ), | |
| 57 | + $icons = $item.find( '.frm-hover-icons' ), | |
| 58 | + $clone; | |
| 59 | + | |
| 60 | + if ( ! $icons.length ) { | |
| 61 | + $clone = jQuery( '#frm-hover-icons-template' ).clone(); | |
| 62 | + $clone.removeAttr( 'id' ); | |
| 63 | + $item.append( $clone ); | |
| 64 | + } | |
| 65 | + | |
| 66 | + $icons.show(); | |
| 67 | + }); | |
| 68 | + | |
| 69 | + jQuery( document ).on( 'mouseout', '#frm_new_form_modal .frm-selectable', function() { | |
| 70 | + var $item = jQuery( this ), | |
| 71 | + $icons = $item.find( '.frm-hover-icons' ); | |
| 72 | + | |
| 73 | + if ( $icons.length ) { | |
| 74 | + $icons.hide(); | |
| 75 | + } | |
| 76 | + }); | |
| 77 | + }, | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Go to upgrade url. | |
| 81 | + * | |
| 82 | + * @since 4.03 | |
| 83 | + */ | |
| 84 | + gotoUpgradeUrl: function() { | |
| 85 | + var w = window.open( frmGlobal.app_url + '/api-connect/', '_blank', 'location=no,width=500,height=730,scrollbars=0' ); | |
| 86 | + w.focus(); | |
| 87 | + }, | |
| 88 | + | |
| 89 | + updateForm: function( response ) { | |
| 90 | + | |
| 91 | + // Start spinner. | |
| 92 | + var btn = el.btn; | |
| 93 | + btn.classList.add( 'frm_loading_button' ); | |
| 94 | + | |
| 95 | + if ( response.url !== '' ) { | |
| 96 | + app.showProgress({ | |
| 97 | + success: true, | |
| 98 | + message: 'Installing...' | |
| 99 | + }); | |
| 100 | + var fallback = setTimeout( function() { | |
| 101 | + app.showProgress({ | |
| 102 | + success: true, | |
| 103 | + message: 'Installing is taking longer than expected. <a class="frm-install-addon button button-primary frm-button-primary" rel="' + response.url + '" aria-label="Install">Install Now</a>' | |
| 104 | + }); | |
| 105 | + }, 10000 ); | |
| 106 | + $.ajax({ | |
| 107 | + type: 'POST', | |
| 108 | + url: ajaxurl, | |
| 109 | + dataType: 'json', | |
| 110 | + data: { | |
| 111 | + action: 'frm_connect', | |
| 112 | + plugin: response.url, | |
| 113 | + nonce: frmGlobal.nonce | |
| 114 | + }, | |
| 115 | + success: function() { | |
| 116 | + clearTimeout( fallback ); | |
| 117 | + app.activateKey( response ); | |
| 118 | + }, | |
| 119 | + error: function( xhr, textStatus, e ) { | |
| 120 | + clearTimeout( fallback ); | |
| 121 | + btn.classList.remove( 'frm_loading_button' ); | |
| 122 | + app.showMessage({ | |
| 123 | + success: false, | |
| 124 | + message: e | |
| 125 | + }); | |
| 126 | + } | |
| 127 | + }); | |
| 128 | + } else if ( response.key !== '' ) { | |
| 129 | + app.activateKey( response ); | |
| 130 | + } | |
| 131 | + }, | |
| 132 | + | |
| 133 | + activateKey: function( response ) { | |
| 134 | + var btn = el.btn; | |
| 135 | + if ( response.key === '' ) { | |
| 136 | + btn.classList.remove( 'frm_loading_button' ); | |
| 137 | + } else { | |
| 138 | + app.showProgress({ | |
| 139 | + success: true, | |
| 140 | + message: 'Activating...' | |
| 141 | + }); | |
| 142 | + $.ajax({ | |
| 143 | + type: 'POST', | |
| 144 | + url: ajaxurl, | |
| 145 | + dataType: 'json', | |
| 146 | + data: { | |
| 147 | + action: 'frm_addon_activate', | |
| 148 | + license: response.key, | |
| 149 | + plugin: 'formidable_pro', | |
| 150 | + wpmu: 0, | |
| 151 | + nonce: frmGlobal.nonce | |
| 152 | + }, | |
| 153 | + success: function( msg ) { | |
| 154 | + btn.classList.remove( 'frm_loading_button' ); | |
| 155 | + | |
| 156 | + if ( msg.success === true ) { | |
| 157 | + el.licenseBox.classList.replace( 'frm_unauthorized_box', 'frm_authorized_box' ); | |
| 158 | + } | |
| 159 | + | |
| 160 | + app.showMessage( msg ); | |
| 161 | + }, | |
| 162 | + error: function( xhr, textStatus, e ) { | |
| 163 | + btn.classList.remove( 'frm_loading_button' ); | |
| 164 | + app.showMessage({ | |
| 165 | + success: false, | |
| 166 | + message: e | |
| 167 | + }); | |
| 168 | + } | |
| 169 | + }); | |
| 170 | + } | |
| 171 | + }, | |
| 172 | + | |
| 173 | + /* Manual license authorization */ | |
| 174 | + authorize: function() { | |
| 175 | + /*jshint validthis:true */ | |
| 176 | + var button = this; | |
| 177 | + var pluginSlug = this.getAttribute( 'data-plugin' ); | |
| 178 | + var input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ); | |
| 179 | + var license = input.value; | |
| 180 | + var wpmu = document.getElementById( 'proplug-wpmu' ); | |
| 181 | + this.classList.add( 'frm_loading_button' ); | |
| 182 | + if ( wpmu === null ) { | |
| 183 | + wpmu = 0; | |
| 184 | + } else if ( wpmu.checked ) { | |
| 185 | + wpmu = 1; | |
| 186 | + } else { | |
| 187 | + wpmu = 0; | |
| 188 | + } | |
| 189 | + | |
| 190 | + $.ajax({ | |
| 191 | + type: 'POST', url: ajaxurl, dataType: 'json', | |
| 192 | + data: { | |
| 193 | + action: 'frm_addon_activate', | |
| 194 | + license: license, | |
| 195 | + plugin: pluginSlug, | |
| 196 | + wpmu: wpmu, | |
| 197 | + nonce: frmGlobal.nonce | |
| 198 | + }, | |
| 199 | + success: function( msg ) { | |
| 200 | + app.afterAuthorize( msg, input ); | |
| 201 | + button.classList.remove( 'frm_loading_button' ); | |
| 202 | + } | |
| 203 | + }); | |
| 204 | + }, | |
| 205 | + | |
| 206 | + afterAuthorize: function( msg, input ) { | |
| 207 | + if ( msg.success === true ) { | |
| 208 | + input.value = '•••••••••••••••••••'; | |
| 209 | + } | |
| 210 | + | |
| 211 | + app.showMessage( msg ); | |
| 212 | + }, | |
| 213 | + | |
| 214 | + showProgress: function( msg ) { | |
| 215 | + var messageBox = el.messageBox; | |
| 216 | + if ( msg.success === true ) { | |
| 217 | + messageBox.classList.remove( 'frm_error_style' ); | |
| 218 | + messageBox.classList.add( 'frm_message', 'frm_updated_message' ); | |
| 219 | + } else { | |
| 220 | + messageBox.classList.add( 'frm_error_style' ); | |
| 221 | + messageBox.classList.remove( 'frm_message', 'frm_updated_message' ); | |
| 222 | + } | |
| 223 | + messageBox.classList.remove( 'frm_hidden' ); | |
| 224 | + messageBox.innerHTML = msg.message; | |
| 225 | + }, | |
| 226 | + | |
| 227 | + showMessage: function( msg ) { | |
| 228 | + var messageBox = el.messageBox; | |
| 229 | + | |
| 230 | + if ( msg.success === true ) { | |
| 231 | + var d = el.licenseBox; | |
| 232 | + d.className = d.className.replace( 'frm_unauthorized_box', 'frm_authorized_box' ); | |
| 233 | + messageBox.classList.remove( 'frm_error_style' ); | |
| 234 | + messageBox.classList.add( 'frm_message', 'frm_updated_message' ); | |
| 235 | + } else { | |
| 236 | + messageBox.classList.add( 'frm_error_style' ); | |
| 237 | + messageBox.classList.remove( 'frm_message', 'frm_updated_message' ); | |
| 238 | + } | |
| 239 | + | |
| 240 | + messageBox.classList.remove( 'frm_hidden' ); | |
| 241 | + messageBox.innerHTML = msg.message; | |
| 242 | + if ( msg.message !== '' ) { | |
| 243 | + setTimeout( function() { | |
| 244 | + messageBox.innerHTML = ''; | |
| 245 | + messageBox.classList.add( 'frm_hidden' ); | |
| 246 | + messageBox.classList.remove( 'frm_error_style', 'frm_message', 'frm_updated_message' ); | |
| 247 | + }, 10000 ); | |
| 248 | + var refreshPage = document.querySelectorAll( '#frm-welcome' ); | |
| 249 | + if ( refreshPage.length > 0 ) { | |
| 250 | + window.location.reload(); | |
| 251 | + } | |
| 252 | + } | |
| 253 | + }, | |
| 254 | + | |
| 255 | + /* Clear the site license cache */ | |
| 256 | + reauthorize: function() { | |
| 257 | + /*jshint validthis:true */ | |
| 258 | + this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>'; | |
| 259 | + | |
| 260 | + $.ajax({ | |
| 261 | + type: 'POST', | |
| 262 | + url: ajaxurl, | |
| 263 | + dataType: 'json', | |
| 264 | + data: { | |
| 265 | + action: 'frm_reset_cache', | |
| 266 | + plugin: 'formidable_pro', | |
| 267 | + nonce: frmGlobal.nonce | |
| 268 | + }, | |
| 269 | + success: function( msg ) { | |
| 270 | + el.reset.innerHTML = msg.message; | |
| 271 | + if ( el.reset.getAttribute( 'data-refresh' ) === '1' ) { | |
| 272 | + window.location.reload(); | |
| 273 | + } | |
| 274 | + } | |
| 275 | + }); | |
| 276 | + return false; | |
| 277 | + }, | |
| 278 | + | |
| 279 | + deauthorize: function() { | |
| 280 | + /*jshint validthis:true */ | |
| 281 | + if ( ! confirm( frmGlobal.deauthorize ) ) { | |
| 282 | + return false; | |
| 283 | + } | |
| 284 | + var pluginSlug = this.getAttribute( 'data-plugin' ), | |
| 285 | + input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ), | |
| 286 | + license = input.value, | |
| 287 | + link = this; | |
| 288 | + | |
| 289 | + this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;"></span>'; | |
| 290 | + | |
| 291 | + $.ajax({ | |
| 292 | + type: 'POST', | |
| 293 | + url: ajaxurl, | |
| 294 | + data: { | |
| 295 | + action: 'frm_addon_deactivate', | |
| 296 | + license: license, | |
| 297 | + plugin: pluginSlug, | |
| 298 | + nonce: frmGlobal.nonce | |
| 299 | + }, | |
| 300 | + success: function() { | |
| 301 | + el.licenseBox.className = el.licenseBox.className.replace( 'frm_authorized_box', 'frm_unauthorized_box' ); | |
| 302 | + input.value = ''; | |
| 303 | + link.innerHTML = ''; | |
| 304 | + } | |
| 305 | + }); | |
| 306 | + return false; | |
| 307 | + } | |
| 308 | + }; | |
| 309 | + | |
| 310 | + // Provide access to public functions/properties. | |
| 311 | + return app; | |
| 312 | + | |
| 313 | +}( document, window, jQuery ) ); | |
| 314 | + | |
| 315 | +function frmAdminBuildJS() { | |
| 316 | + //'use strict'; | |
| 317 | + | |
| 318 | + /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl */ | |
| 319 | + | |
| 320 | + var $newFields = jQuery( document.getElementById( 'frm-show-fields' ) ), | |
| 321 | + builderForm = document.getElementById( 'new_fields' ), | |
| 322 | + thisForm = document.getElementById( 'form_id' ), | |
| 323 | + cancelSort = false, | |
| 324 | + copyHelper = false, | |
| 325 | + fieldsUpdated = 0, | |
| 326 | + thisFormId = 0, | |
| 327 | + autoId = 0, | |
| 328 | + optionMap = {}, | |
| 329 | + lastNewActionIdReturned = 0, | |
| 330 | + __ = wp.i18n.__; | |
| 331 | + | |
| 332 | + if ( thisForm !== null ) { | |
| 333 | + thisFormId = thisForm.value; | |
| 334 | + } | |
| 335 | + | |
| 336 | + // Global settings | |
| 337 | + var s; | |
| 338 | + | |
| 339 | + function showElement( element ) { | |
| 340 | + element[0].style.display = ''; | |
| 341 | + } | |
| 342 | + | |
| 343 | + function hideElement( element ) { | |
| 344 | + element[0].style.display = 'none'; | |
| 345 | + } | |
| 346 | + | |
| 347 | + function empty( $obj ) { | |
| 348 | + if ( $obj !== null ) { | |
| 349 | + while ( $obj.firstChild ) { | |
| 350 | + $obj.removeChild( $obj.firstChild ); | |
| 351 | + } | |
| 352 | + } | |
| 353 | + } | |
| 354 | + | |
| 355 | + function addClass( $obj, className ) { | |
| 356 | + if ( $obj.classList ) { | |
| 357 | + $obj.classList.add( className ); | |
| 358 | + } else { | |
| 359 | + $obj.className += ' ' + className; | |
| 360 | + } | |
| 361 | + } | |
| 362 | + | |
| 363 | + function confirmClick( e ) { | |
| 364 | + /*jshint validthis:true */ | |
| 365 | + e.stopPropagation(); | |
| 366 | + e.preventDefault(); | |
| 367 | + confirmLinkClick( this ); | |
| 368 | + } | |
| 369 | + | |
| 370 | + function confirmLinkClick( link ) { | |
| 371 | + var message = link.getAttribute( 'data-frmverify' ); | |
| 372 | + | |
| 373 | + if ( message === null || link.id === 'frm-confirmed-click' ) { | |
| 374 | + return true; | |
| 375 | + } else { | |
| 376 | + return confirmModal( link ); | |
| 377 | + } | |
| 378 | + } | |
| 379 | + | |
| 380 | + function confirmModal( link ) { | |
| 381 | + var caution, verify, $confirmMessage, frmCaution, i, dataAtts, | |
| 382 | + $info = initModal( '#frm_confirm_modal', '400px' ), | |
| 383 | + continueButton = document.getElementById( 'frm-confirmed-click' ); | |
| 384 | + | |
| 385 | + if ( $info === false ) { | |
| 386 | + return false; | |
| 387 | + } | |
| 388 | + | |
| 389 | + caution = link.getAttribute( 'data-frmcaution' ); | |
| 390 | + verify = link.getAttribute( 'data-frmverify' ); | |
| 391 | + $confirmMessage = jQuery( '.frm-confirm-msg' ); | |
| 392 | + $confirmMessage.empty(); | |
| 393 | + | |
| 394 | + if ( caution ) { | |
| 395 | + frmCaution = document.createElement( 'div' ); | |
| 396 | + frmCaution.classList.add( 'frm-caution' ); | |
| 397 | + frmCaution.appendChild( document.createTextNode( caution ) ); | |
| 398 | + $confirmMessage.append( frmCaution ); | |
| 399 | + } | |
| 400 | + | |
| 401 | + if ( verify ) { | |
| 402 | + $confirmMessage.append( document.createTextNode( verify ) ); | |
| 403 | + } | |
| 404 | + | |
| 405 | + removeAtts = continueButton.dataset; | |
| 406 | + for ( i in dataAtts ) { | |
| 407 | + continueButton.removeAttribute( 'data-' + i ); | |
| 408 | + } | |
| 409 | + | |
| 410 | + dataAtts = link.dataset; | |
| 411 | + for ( i in dataAtts ) { | |
| 412 | + if ( i !== 'frmverify' ) { | |
| 413 | + continueButton.setAttribute( 'data-' + i, dataAtts[i]); | |
| 414 | + } | |
| 415 | + } | |
| 416 | + | |
| 417 | + $info.dialog( 'open' ); | |
| 418 | + continueButton.setAttribute( 'href', link.getAttribute( 'href' ) ); | |
| 419 | + return false; | |
| 420 | + } | |
| 421 | + | |
| 422 | + function infoModal( msg ) { | |
| 423 | + var $info = initModal( '#frm_info_modal', '400px' ); | |
| 424 | + | |
| 425 | + if ( $info === false ) { | |
| 426 | + return false; | |
| 427 | + } | |
| 428 | + | |
| 429 | + jQuery( '.frm-info-msg' ).html( msg ); | |
| 430 | + | |
| 431 | + $info.dialog( 'open' ); | |
| 432 | + return false; | |
| 433 | + } | |
| 434 | + | |
| 435 | + function toggleItem( e ) { | |
| 436 | + /*jshint validthis:true */ | |
| 437 | + var toggle = this.getAttribute( 'data-frmtoggle' ), | |
| 438 | + text = this.getAttribute( 'data-toggletext' ), | |
| 439 | + items = jQuery( toggle ); | |
| 440 | + | |
| 441 | + e.preventDefault(); | |
| 442 | + | |
| 443 | + if ( items.is( ':visible' ) ) { | |
| 444 | + items.show(); | |
| 445 | + } else { | |
| 446 | + items.hide(); | |
| 447 | + } | |
| 448 | + | |
| 449 | + if ( text !== null && text !== '' ) { | |
| 450 | + this.setAttribute( 'data-toggletext', this.innerHTML ); | |
| 451 | + this.innerHTML = text; | |
| 452 | + } | |
| 453 | + | |
| 454 | + return false; | |
| 455 | + } | |
| 456 | + | |
| 457 | + function hideShowItem( e ) { | |
| 458 | + /*jshint validthis:true */ | |
| 459 | + var hide = this.getAttribute( 'data-frmhide' ), | |
| 460 | + show = this.getAttribute( 'data-frmshow' ), | |
| 461 | + toggleClass = this.getAttribute( 'data-toggleclass' ); | |
| 462 | + | |
| 463 | + e.preventDefault(); | |
| 464 | + if ( toggleClass === null ) { | |
| 465 | + toggleClass = 'frm_hidden'; | |
| 466 | + } | |
| 467 | + | |
| 468 | + if ( hide !== null ) { | |
| 469 | + jQuery( hide ).addClass( toggleClass ); | |
| 470 | + } | |
| 471 | + | |
| 472 | + if ( show !== null ) { | |
| 473 | + jQuery( show ).removeClass( toggleClass ); | |
| 474 | + } | |
| 475 | + | |
| 476 | + var current = this.parentNode.querySelectorAll( 'a.current' ); | |
| 477 | + if ( current !== null ) { | |
| 478 | + for ( var i = 0; i < current.length; i++ ) { | |
| 479 | + current[ i ].classList.remove( 'current' ); | |
| 480 | + } | |
| 481 | + this.classList.add( 'current' ); | |
| 482 | + } | |
| 483 | + | |
| 484 | + return false; | |
| 485 | + } | |
| 486 | + | |
| 487 | + function setupMenuOffset() { | |
| 488 | + window.onscroll = document.documentElement.onscroll = setMenuOffset; | |
| 489 | + setMenuOffset(); | |
| 490 | + } | |
| 491 | + | |
| 492 | + function setMenuOffset() { | |
| 493 | + var fields = document.getElementById( 'frm_adv_info' ); | |
| 494 | + if ( fields === null ) { | |
| 495 | + return; | |
| 496 | + } | |
| 497 | + | |
| 498 | + var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari | |
| 499 | + if ( currentOffset === 0 ) { | |
| 500 | + fields.classList.remove( 'frm_fixed' ); | |
| 501 | + return; | |
| 502 | + } | |
| 503 | + | |
| 504 | + var posEle = document.getElementById( 'frm_position_ele' ); | |
| 505 | + if ( posEle === null ) { | |
| 506 | + return; | |
| 507 | + } | |
| 508 | + | |
| 509 | + var eleOffset = jQuery( posEle ).offset(); | |
| 510 | + var offset = eleOffset.top; | |
| 511 | + var desiredOffset = offset - currentOffset; | |
| 512 | + var menuHeight = 0; | |
| 513 | + | |
| 514 | + var menu = document.getElementById( 'wpadminbar' ); | |
| 515 | + if ( menu !== null ) { | |
| 516 | + menuHeight = menu.offsetHeight; | |
| 517 | + } | |
| 518 | + | |
| 519 | + if ( desiredOffset < menuHeight ) { | |
| 520 | + desiredOffset = menuHeight; | |
| 521 | + } | |
| 522 | + | |
| 523 | + if ( desiredOffset > menuHeight ) { | |
| 524 | + fields.classList.remove( 'frm_fixed' ); | |
| 525 | + } else { | |
| 526 | + fields.classList.add( 'frm_fixed' ); | |
| 527 | + if ( desiredOffset !== 32 ) { | |
| 528 | + fields.style.top = desiredOffset + 'px'; | |
| 529 | + } | |
| 530 | + } | |
| 531 | + } | |
| 532 | + | |
| 533 | + function loadTooltips() { | |
| 534 | + var wrapClass = jQuery( '.wrap, .frm_wrap' ), | |
| 535 | + confirmModal = document.getElementById( 'frm_confirm_modal' ), | |
| 536 | + doAction = false, | |
| 537 | + confirmedBulkDelete = false; | |
| 538 | + | |
| 539 | + jQuery( confirmModal ).on( 'click', '[data-deletefield]', deleteFieldConfirmed ); | |
| 540 | + jQuery( confirmModal ).on( 'click', '[data-removeid]', removeThisTag ); | |
| 541 | + jQuery( confirmModal ).on( 'click', '[data-trashtemplate]', trashTemplate ); | |
| 542 | + | |
| 543 | + wrapClass.on( 'click', '.frm_remove_tag, .frm_remove_form_action', removeThisTag ); | |
| 544 | + wrapClass.on( 'click', 'a[data-frmverify]', confirmClick ); | |
| 545 | + wrapClass.on( 'click', 'a[data-frmtoggle]', toggleItem ); | |
| 546 | + wrapClass.on( 'click', 'a[data-frmhide], a[data-frmshow]', hideShowItem ); | |
| 547 | + wrapClass.on( 'click', '.widget-top,a.widget-action', clickWidget ); | |
| 548 | + | |
| 549 | + wrapClass.on( 'mouseenter.frm', '.frm_bstooltip, .frm_help', function() { | |
| 550 | + jQuery( this ).off( 'mouseenter.frm' ); | |
| 551 | + | |
| 552 | + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( ); | |
| 553 | + jQuery( this ).tooltip( 'show' ); | |
| 554 | + }); | |
| 555 | + | |
| 556 | + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( ); | |
| 557 | + | |
| 558 | + jQuery( document ).on( 'click', '#doaction, #doaction2', function( event ) { | |
| 559 | + var isTop = this.id === 'doaction', | |
| 560 | + suffix = isTop ? 'top' : 'bottom', | |
| 561 | + bulkActionSelector = document.getElementById( 'bulk-action-selector-' + suffix ), | |
| 562 | + confirmBulkDelete = document.getElementById( 'confirm-bulk-delete-' + suffix ); | |
| 563 | + | |
| 564 | + if ( bulkActionSelector !== null && confirmBulkDelete !== null ) { | |
| 565 | + doAction = this; | |
| 566 | + | |
| 567 | + if ( ! confirmedBulkDelete && bulkActionSelector.value === 'bulk_delete' ) { | |
| 568 | + event.preventDefault(); | |
| 569 | + confirmLinkClick( confirmBulkDelete ); | |
| 570 | + return false; | |
| 571 | + } | |
| 572 | + } else { | |
| 573 | + doAction = false; | |
| 574 | + } | |
| 575 | + }); | |
| 576 | + | |
| 577 | + jQuery( document ).on( 'click', '#frm-confirmed-click', function( event ) { | |
| 578 | + if ( doAction === false ) { | |
| 579 | + return; | |
| 580 | + } | |
| 581 | + | |
| 582 | + if ( this.getAttribute( 'href' ) === 'confirm-bulk-delete' ) { | |
| 583 | + event.preventDefault(); | |
| 584 | + confirmedBulkDelete = true; | |
| 585 | + doAction.click(); | |
| 586 | + return false; | |
| 587 | + } | |
| 588 | + }); | |
| 589 | + } | |
| 590 | + | |
| 591 | + function removeThisTag() { | |
| 592 | + /*jshint validthis:true */ | |
| 593 | + var show, hide, removeMore, | |
| 594 | + id = '', | |
| 595 | + deleteButton = jQuery( this ), | |
| 596 | + continueRemove = confirmLinkClick( this ); | |
| 597 | + | |
| 598 | + if ( continueRemove === false ) { | |
| 599 | + return; | |
| 600 | + } else { | |
| 601 | + id = deleteButton.attr( 'data-removeid' ); | |
| 602 | + show = deleteButton.attr( 'data-showlast' ); | |
| 603 | + removeMore = deleteButton.attr( 'data-removemore' ); | |
| 604 | + if ( typeof show === 'undefined' ) { | |
| 605 | + show = ''; | |
| 606 | + } | |
| 607 | + hide = deleteButton.attr( 'data-hidelast' ); | |
| 608 | + if ( typeof hide === 'undefined' ) { | |
| 609 | + hide = ''; | |
| 610 | + } | |
| 611 | + } | |
| 612 | + | |
| 613 | + if ( show !== '' ) { | |
| 614 | + if ( deleteButton.closest( '.frm_add_remove' ).find( '.frm_remove_tag:visible' ).length > 1 ) { | |
| 615 | + show = ''; | |
| 616 | + hide = ''; | |
| 617 | + } | |
| 618 | + } else if ( id.indexOf( 'frm_postmeta_' ) === 0 ) { | |
| 619 | + if ( jQuery( '#frm_postmeta_rows .frm_postmeta_row' ).length < 2 ) { | |
| 620 | + show = '.frm_add_postmeta_row.button'; | |
| 621 | + } | |
| 622 | + if ( jQuery( '.frm_toggle_cf_opts' ).length && jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().length ) { | |
| 623 | + if ( show !== '' ) { | |
| 624 | + show += ','; | |
| 625 | + } | |
| 626 | + show += '#' + jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().attr( 'id' ) + ' .frm_toggle_cf_opts'; | |
| 627 | + } | |
| 628 | + } | |
| 629 | + | |
| 630 | + var $fadeEle = jQuery( document.getElementById( id ) ); | |
| 631 | + $fadeEle.fadeOut( 400, function() { | |
| 632 | + $fadeEle.remove(); | |
| 633 | + fieldUpdated(); | |
| 634 | + | |
| 635 | + if ( hide !== '' ) { | |
| 636 | + jQuery( hide ).hide(); | |
| 637 | + } | |
| 638 | + | |
| 639 | + if ( show !== '' ) { | |
| 640 | + jQuery( show + ' a,' + show ).removeClass( 'frm_hidden' ).fadeIn( 'slow' ); | |
| 641 | + } | |
| 642 | + | |
| 643 | + var action = jQuery( this ).closest( '.frm_form_action_settings' ); | |
| 644 | + if ( typeof action !== 'undefined' ) { | |
| 645 | + var type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(); | |
| 646 | + checkActiveAction( type ); | |
| 647 | + } | |
| 648 | + }); | |
| 649 | + | |
| 650 | + if ( typeof removeMore !== 'undefined' ) { | |
| 651 | + removeMore = jQuery( removeMore ); | |
| 652 | + removeMore.fadeOut( 400, function() { | |
| 653 | + removeMore.remove(); | |
| 654 | + }); | |
| 655 | + } | |
| 656 | + | |
| 657 | + if ( show !== '' ) { | |
| 658 | + jQuery( this ).closest( '.frm_logic_rows' ).fadeOut( 'slow' ); | |
| 659 | + } | |
| 660 | + | |
| 661 | + return false; | |
| 662 | + } | |
| 663 | + | |
| 664 | + function clickWidget( event, b ) { | |
| 665 | + /*jshint validthis:true */ | |
| 666 | + var target = event.target; | |
| 667 | + if ( typeof b === 'undefined' ) { | |
| 668 | + b = this; | |
| 669 | + } | |
| 670 | + | |
| 671 | + popCalcFields( b, false ); | |
| 672 | + | |
| 673 | + var cont = jQuery( b ).closest( '.frm_form_action_settings' ); | |
| 674 | + if ( cont.length && typeof target !== 'undefined' ) { | |
| 675 | + var className = target.parentElement.className; | |
| 676 | + if ( 'string' === typeof className ) { | |
| 677 | + if ( className.indexOf( 'frm_email_icons' ) > -1 || className.indexOf( 'frm_toggle' ) > -1 ) { | |
| 678 | + // clicking on delete icon shouldn't open it | |
| 679 | + event.stopPropagation(); | |
| 680 | + return; | |
| 681 | + } | |
| 682 | + } | |
| 683 | + } | |
| 684 | + | |
| 685 | + var inside = cont.children( '.widget-inside' ); | |
| 686 | + | |
| 687 | + if ( cont.length && inside.find( 'p, div, table' ).length < 1 ) { | |
| 688 | + var actionId = cont.find( 'input[name$="[ID]"]' ).val(); | |
| 689 | + var actionType = cont.find( 'input[name$="[post_excerpt]"]' ).val(); | |
| 690 | + if ( actionType ) { | |
| 691 | + inside.html( '<span class="frm-wait frm_spinner"></span>' ); | |
| 692 | + cont.find( '.spinner' ).fadeIn( 'slow' ); | |
| 693 | + jQuery.ajax({ | |
| 694 | + type: 'POST', | |
| 695 | + url: ajaxurl, | |
| 696 | + data: { | |
| 697 | + action: 'frm_form_action_fill', | |
| 698 | + action_id: actionId, | |
| 699 | + action_type: actionType, | |
| 700 | + nonce: frmGlobal.nonce | |
| 701 | + }, | |
| 702 | + success: function( html ) { | |
| 703 | + inside.html( html ); | |
| 704 | + initiateMultiselect(); | |
| 705 | + showInputIcon( '#' + cont.attr( 'id' ) ); | |
| 706 | + initAutocomplete( 'page', inside ); | |
| 707 | + jQuery( b ).trigger( 'frm-action-loaded' ); | |
| 708 | + } | |
| 709 | + }); | |
| 710 | + } | |
| 711 | + } | |
| 712 | + | |
| 713 | + jQuery( b ).closest( '.frm_field_box' ).siblings().find( '.widget-inside' ).slideUp( 'fast' ); | |
| 714 | + if ( ( typeof b.className !== 'undefined' && b.className.indexOf( 'widget-action' ) !== -1 ) || jQuery( b ).closest( '.start_divider' ).length < 1 ) { | |
| 715 | + return; | |
| 716 | + } | |
| 717 | + | |
| 718 | + inside = jQuery( b ).closest( 'div.widget' ).children( '.widget-inside' ); | |
| 719 | + if ( inside.is( ':hidden' ) ) { | |
| 720 | + inside.slideDown( 'fast' ); | |
| 721 | + } else { | |
| 722 | + inside.slideUp( 'fast' ); | |
| 723 | + } | |
| 724 | + } | |
| 725 | + | |
| 726 | + function clickNewTab() { | |
| 727 | + /*jshint validthis:true */ | |
| 728 | + var t = this.getAttribute( 'href' ), | |
| 729 | + c = t.replace( '#', '.' ), | |
| 730 | + $link = jQuery( this ); | |
| 731 | + | |
| 732 | + if ( typeof t === 'undefined' ) { | |
| 733 | + return false; | |
| 734 | + } | |
| 735 | + | |
| 736 | + $link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' ); | |
| 737 | + $link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide(); | |
| 738 | + document.getElementById( t.replace( '#', '' ) ).style.display = 'block'; | |
| 739 | + | |
| 740 | + if ( this.id === 'frm_insert_fields_tab' ) { | |
| 741 | + clearSettingsBox(); | |
| 742 | + } | |
| 743 | + return false; | |
| 744 | + } | |
| 745 | + | |
| 746 | + function clickTab( link, auto ) { | |
| 747 | + link = jQuery( link ); | |
| 748 | + var t = link.attr( 'href' ); | |
| 749 | + if ( typeof t === 'undefined' ) { | |
| 750 | + return; | |
| 751 | + } | |
| 752 | + | |
| 753 | + var c = t.replace( '#', '.' ); | |
| 754 | + | |
| 755 | + link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' ); | |
| 756 | + if ( link.closest( 'div' ).find( '.tabs-panel' ).length ) { | |
| 757 | + link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide(); | |
| 758 | + } else { | |
| 759 | + if ( document.getElementById( 'form_global_settings' ) !== null ) { | |
| 760 | + /* global settings */ | |
| 761 | + var ajax = link.data( 'frmajax' ); | |
| 762 | + link.closest( '.frm_wrap' ).find( '.tabs-panel, .hide_with_tabs' ).hide(); | |
| 763 | + if ( typeof ajax !== 'undefined' && ajax == '1' ) { | |
| 764 | + loadSettingsTab( t ); | |
| 765 | + } | |
| 766 | + } else { | |
| 767 | + /* form settings page */ | |
| 768 | + jQuery( '#frm-categorydiv .tabs-panel, .hide_with_tabs' ).hide(); | |
| 769 | + } | |
| 770 | + } | |
| 771 | + jQuery( t ).show(); | |
| 772 | + jQuery( c ).show(); | |
| 773 | + | |
| 774 | + hideShortcodes(); | |
| 775 | + | |
| 776 | + if ( auto !== 'auto' ) { | |
| 777 | + // Hide success message on tab change. | |
| 778 | + jQuery( '.frm_updated_message' ).hide(); | |
| 779 | + jQuery( '.frm_warning_style' ).hide(); | |
| 780 | + } | |
| 781 | + | |
| 782 | + if ( jQuery( link ).closest( '#frm_adv_info' ).length ) { | |
| 783 | + return; | |
| 784 | + } | |
| 785 | + | |
| 786 | + if ( jQuery( '.frm_form_settings' ).length ) { | |
| 787 | + jQuery( '.frm_form_settings' ).attr( 'action', '?page=formidable&frm_action=settings&id=' + jQuery( '.frm_form_settings input[name="id"]' ).val() + '&t=' + t.replace( '#', '' ) ); | |
| 788 | + } else { | |
| 789 | + jQuery( '.frm_settings_form' ).attr( 'action', '?page=formidable-settings&t=' + t.replace( '#', '' ) ); | |
| 790 | + } | |
| 791 | + } | |
| 792 | + | |
| 793 | + /* Form Builder */ | |
| 794 | + function setupSortable( sort ) { | |
| 795 | + var startSort, container, $previousFieldContainer, opts; | |
| 796 | + | |
| 797 | + startSort = false; | |
| 798 | + container = jQuery( '#post-body-content' ); | |
| 799 | + | |
| 800 | + opts = { | |
| 801 | + connectWith: 'ul.frm_sorting', | |
| 802 | + items: 'li.frm_field_box', | |
| 803 | + placeholder: 'sortable-placeholder', | |
| 804 | + axis: 'y', | |
| 805 | + cancel: '.widget,.frm_field_opts_list,input,textarea,select,.edit_field_type_end_divider,.frm_sortable_field_opts,.frm_noallow', | |
| 806 | + accepts: 'field_type_list', | |
| 807 | + forcePlaceholderSize: false, | |
| 808 | + tolerance: 'pointer', | |
| 809 | + handle: '.frm-move', | |
| 810 | + over: function() { | |
| 811 | + this.classList.add( 'drop-me' ); | |
| 812 | + }, | |
| 813 | + out: function() { | |
| 814 | + this.classList.remove( 'drop-me' ); | |
| 815 | + }, | |
| 816 | + receive: function( event, ui ) { | |
| 817 | + // Receive event occurs when an item in one sortable list is dragged into another sortable list | |
| 818 | + | |
| 819 | + if ( cancelSort ) { | |
| 820 | + ui.item.addClass( 'frm_cancel_sort' ); | |
| 821 | + return; | |
| 822 | + } | |
| 823 | + | |
| 824 | + if ( typeof ui.item.attr( 'id' ) !== 'undefined' ) { | |
| 825 | + if ( ui.item.attr( 'id' ).indexOf( 'frm_field_id' ) > -1 ) { | |
| 826 | + // An existing field was dragged and dropped into, out of, or between sections | |
| 827 | + updateFieldAfterMovingBetweenSections( ui.item ); | |
| 828 | + } else { | |
| 829 | + // A new field was dragged into the form | |
| 830 | + insertNewFieldByDragging( this, ui.item, opts ); | |
| 831 | + } | |
| 832 | + } | |
| 833 | + }, | |
| 834 | + change: function( event, ui ) { | |
| 835 | + // don't allow some field types inside section | |
| 836 | + if ( allowDrop( ui ) ) { | |
| 837 | + ui.placeholder.addClass( 'sortable-placeholder' ).removeClass( 'no-drop-placeholder' ); | |
| 838 | + cancelSort = false; | |
| 839 | + } else { | |
| 840 | + ui.placeholder.addClass( 'no-drop-placeholder' ).removeClass( 'sortable-placeholder' ); | |
| 841 | + cancelSort = true; | |
| 842 | + } | |
| 843 | + }, | |
| 844 | + start: function( event, ui ) { | |
| 845 | + unselectFieldGroups(); | |
| 846 | + deleteEmptyDividerWrappers(); | |
| 847 | + maybeRemoveGroupHoverTarget(); | |
| 848 | + closeOpenFieldDropdowns(); | |
| 849 | + container.get( 0 ).classList.add( 'frm-dragging-field' ); | |
| 850 | + if ( ui.item[0].offsetHeight > 120 ) { | |
| 851 | + jQuery( sort ).sortable( 'refreshPositions' ); | |
| 852 | + } | |
| 853 | + if ( ui.item[0].classList.contains( 'frm-page-collapsed' ) ) { | |
| 854 | + // If a page if collapsed, expand it before dragging since only the page break will move. | |
| 855 | + toggleCollapsePage( jQuery( ui.item[0]) ); | |
| 856 | + } | |
| 857 | + $previousFieldContainer = ui.item.closest( 'ul.frm_sorting' ); | |
| 858 | + }, | |
| 859 | + helper: function( e, li ) { | |
| 860 | + copyHelper = li.clone().insertAfter( li ); | |
| 861 | + return li.clone().addClass( 'frm-sortable-helper' ); | |
| 862 | + }, | |
| 863 | + beforeStop: function( event, ui ) { | |
| 864 | + // If this was dropped at the beginning of a collpased page, open it. | |
| 865 | + var previous = ui.item[0].previousElementSibling; | |
| 866 | + if ( previous !== null && previous.classList.contains( 'frm-page-collapsed' ) ) { | |
| 867 | + toggleCollapsePage( jQuery( previous ) ); | |
| 868 | + } | |
| 869 | + }, | |
| 870 | + stop: function( event, ui ) { | |
| 871 | + var moving, $previousContainerFields, $closestFieldBox; | |
| 872 | + | |
| 873 | + container.get( 0 ).classList.remove( 'frm-dragging-field' ); | |
| 874 | + moving = jQuery( this ); | |
| 875 | + copyHelper && copyHelper.remove(); | |
| 876 | + | |
| 877 | + if ( cancelSort ) { | |
| 878 | + moving.sortable( 'cancel' ); | |
| 879 | + syncAfterDragAndDrop(); | |
| 880 | + return; | |
| 881 | + } | |
| 882 | + | |
| 883 | + $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : []; | |
| 884 | + if ( $previousFieldContainer.length ) { | |
| 885 | + if ( ! $previousContainerFields.length ) { | |
| 886 | + $closestFieldBox = $previousFieldContainer.closest( 'li.frm_field_box' ); | |
| 887 | + if ( ! $closestFieldBox.hasClass( 'edit_field_type_divider' ) ) { | |
| 888 | + // remove an empty field group, but don't remove an empty section. | |
| 889 | + $closestFieldBox.remove(); | |
| 890 | + } | |
| 891 | + } else { | |
| 892 | + syncLayoutClasses( $previousContainerFields.first() ); | |
| 893 | + } | |
| 894 | + } | |
| 895 | + | |
| 896 | + if ( ( 'frm-show-fields' === ui.item.parent().attr( 'id' ) || ui.item.parent().hasClass( 'start_divider' ) ) && ui.item.hasClass( 'form-field' ) ) { | |
| 897 | + // dragging an item into a new row. | |
| 898 | + wrapFieldLiInPlace( ui.item ); | |
| 899 | + if ( $previousContainerFields.length ) { | |
| 900 | + // only if the previous container had other sibling fields, remove the previous layout class. | |
| 901 | + syncLayoutClasses( ui.item ); | |
| 902 | + } | |
| 903 | + } else { | |
| 904 | + syncLayoutClasses( ui.item ); | |
| 905 | + } | |
| 906 | + | |
| 907 | + syncAfterDragAndDrop(); | |
| 908 | + }, | |
| 909 | + sort: function( event, ui ) { | |
| 910 | + var $row, $children, $lastChild, currentIndex, left; | |
| 911 | + | |
| 912 | + container.scrollTop( function( i, v ) { | |
| 913 | + var moved, h, relativePos, y; | |
| 914 | + | |
| 915 | + if ( startSort === false ) { | |
| 916 | + startSort = event.clientY; | |
| 917 | + return v; | |
| 918 | + } | |
| 919 | + | |
| 920 | + moved = event.clientY - startSort; | |
| 921 | + h = this.offsetHeight; | |
| 922 | + relativePos = event.clientY - this.offsetTop; | |
| 923 | + y = relativePos - h / 2; | |
| 924 | + if ( relativePos > ( h - 50 ) && moved > 5 ) { | |
| 925 | + // scrolling down | |
| 926 | + return v + y * 0.1; | |
| 927 | + } else if ( relativePos < 50 && moved < -5 ) { | |
| 928 | + //scrolling up | |
| 929 | + return v - Math.abs( y * 0.1 ); | |
| 930 | + } | |
| 931 | + }); | |
| 932 | + | |
| 933 | + maybeFixPlaceholderParent( ui, event ); | |
| 934 | + | |
| 935 | + $row = ui.placeholder.parent(); | |
| 936 | + $children = getFieldsInRow( $row ); | |
| 937 | + currentIndex = determineIndexBasedOffOfMousePositionInRow( $row, event.clientX ); | |
| 938 | + | |
| 939 | + if ( ! $children.length ) { | |
| 940 | + return; | |
| 941 | + } | |
| 942 | + | |
| 943 | + if ( currentIndex === $children.length ) { | |
| 944 | + $lastChild = jQuery( $children.get( currentIndex - 1 ) ); | |
| 945 | + left = $lastChild.offset().left - ui.placeholder.parent().offset().left + $lastChild.outerWidth(); | |
| 946 | + $row.append( ui.placeholder ); | |
| 947 | + } else { | |
| 948 | + left = jQuery( $children.get( currentIndex ) ).offset().left - $row.offset().left; | |
| 949 | + jQuery( $children.get( currentIndex ) ).before( ui.placeholder ); | |
| 950 | + } | |
| 951 | + | |
| 952 | + ui.placeholder.get( 0 ).style.left = left + 'px'; | |
| 953 | + } | |
| 954 | + }; | |
| 955 | + | |
| 956 | + jQuery( sort ).sortable( opts ); | |
| 957 | + | |
| 958 | + setupFieldOptionSorting( jQuery( '#frm_builder_page' ) ); | |
| 959 | + } | |
| 960 | + | |
| 961 | + function syncAfterDragAndDrop() { | |
| 962 | + maybeRemoveNewCancelledFields(); | |
| 963 | + maybeUncancelFields(); | |
| 964 | + maybeFixEndDividers(); | |
| 965 | + fixUnwrappedListItems(); | |
| 966 | + toggleSectionHolder(); | |
| 967 | + updateFieldOrder(); | |
| 968 | + } | |
| 969 | + | |
| 970 | + function maybeRemoveNewCancelledFields() { | |
| 971 | + Array.from( document.getElementById( 'frm-show-fields' ).children ).forEach( | |
| 972 | + function( fieldBox ) { | |
| 973 | + if ( fieldBox.classList.contains( 'frmbutton' ) && fieldBox.classList.contains( 'ui-draggable' ) ) { | |
| 974 | + fieldBox.remove(); | |
| 975 | + } | |
| 976 | + } | |
| 977 | + ); | |
| 978 | + } | |
| 979 | + | |
| 980 | + function maybeUncancelFields() { | |
| 981 | + document.querySelectorAll( '.frm_cancel_sort' ).forEach( | |
| 982 | + function( field ) { | |
| 983 | + field.classList.remove( 'frm_cancel_sort' ); | |
| 984 | + } | |
| 985 | + ); | |
| 986 | + } | |
| 987 | + | |
| 988 | + /** | |
| 989 | + * Make sure the end dividers are always a child of a start divider, at the bottom at the list. | |
| 990 | + */ | |
| 991 | + function maybeFixEndDividers() { | |
| 992 | + var endDividers = document.querySelectorAll( '.edit_field_type_end_divider' ); | |
| 993 | + if ( ! endDividers.length ) { | |
| 994 | + return; | |
| 995 | + } | |
| 996 | + endDividers.forEach( | |
| 997 | + function( endDivider ) { | |
| 998 | + if ( endDivider.parentNode.classList.contains( 'start_divider' ) ) { | |
| 999 | + // avoid having to call closest, but still append it as it might not be the last child. | |
| 1000 | + endDivider.parentNode.appendChild( endDivider ); | |
| 1001 | + return; | |
| 1002 | + } | |
| 1003 | + endDivider.closest( '.start_divider' ).appendChild( endDivider ); | |
| 1004 | + } | |
| 1005 | + ); | |
| 1006 | + } | |
| 1007 | + | |
| 1008 | + /** | |
| 1009 | + * Sortable struggles to put the field into the proper section if there are multiple in a field group. This helps fix some of those issues. | |
| 1010 | + */ | |
| 1011 | + function maybeFixPlaceholderParent( ui, event ) { | |
| 1012 | + var elementFromPoint, wrapper, shouldAppend; | |
| 1013 | + elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 1014 | + if ( null === elementFromPoint ) { | |
| 1015 | + return; | |
| 1016 | + } | |
| 1017 | + wrapper = elementFromPoint.closest( '.frm_sorting' ); | |
| 1018 | + if ( null === wrapper ) { | |
| 1019 | + return; | |
| 1020 | + } | |
| 1021 | + if ( ui.placeholder.closest( '.start_divider' ).parent().parent().find( '.start_divider' ).length < 2 ) { | |
| 1022 | + // placeholder is not in a problematic position that needs to be fixed so leave it. | |
| 1023 | + return; | |
| 1024 | + } | |
| 1025 | + shouldAppend = false; | |
| 1026 | + if ( wrapper.classList.contains( 'start_divider' ) ) { | |
| 1027 | + shouldAppend = jQuery( wrapper ).parent().parent().find( '.start_divider' ).length >= 2; | |
| 1028 | + } else if ( null !== wrapper.closest( '.start_divider' ) ) { | |
| 1029 | + shouldAppend = jQuery( wrapper ).closest( '.start_divider' ).parent().parent().find( '.start_divider' ).length >= 2; | |
| 1030 | + } | |
| 1031 | + if ( null !== wrapper.closest( '.frm-sortable-helper' ) ) { | |
| 1032 | + // avoid ever appending to the sortable helper. | |
| 1033 | + return; | |
| 1034 | + } | |
| 1035 | + if ( shouldAppend ) { | |
| 1036 | + // TODO instead of appendTo, we might need to look for the closest item, and appear above/below it. | |
| 1037 | + ui.placeholder.appendTo( wrapper ); | |
| 1038 | + } | |
| 1039 | + } | |
| 1040 | + | |
| 1041 | + function fixUnwrappedListItems() { | |
| 1042 | + document.querySelectorAll( 'ul.start_divider > li.form-field:not(.edit_field_type_end_divider)' ).forEach( | |
| 1043 | + function( field ) { | |
| 1044 | + wrapFieldLiInPlace( field ); | |
| 1045 | + } | |
| 1046 | + ); | |
| 1047 | + } | |
| 1048 | + | |
| 1049 | + function deleteEmptyDividerWrappers() { | |
| 1050 | + var dividers = document.querySelectorAll( 'ul.start_divider' ); | |
| 1051 | + if ( ! dividers.length ) { | |
| 1052 | + return; | |
| 1053 | + } | |
| 1054 | + dividers.forEach( | |
| 1055 | + function( divider ) { | |
| 1056 | + var children = [].slice.call( divider.children ); | |
| 1057 | + children.forEach( | |
| 1058 | + function( child ) { | |
| 1059 | + if ( 0 === child.children.length ) { | |
| 1060 | + child.remove(); | |
| 1061 | + } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) { | |
| 1062 | + child.remove(); | |
| 1063 | + } | |
| 1064 | + } | |
| 1065 | + ); | |
| 1066 | + } | |
| 1067 | + ); | |
| 1068 | + } | |
| 1069 | + | |
| 1070 | + /** | |
| 1071 | + * @returns {bool} true if the placeholder parent should be fixed. | |
| 1072 | + */ | |
| 1073 | + function shouldTryFixingPlaceholderParent( $placeholder ) { | |
| 1074 | + var closestSection = $placeholder.closest( '.start_divider' ); | |
| 1075 | + if ( null === closestSection ) { | |
| 1076 | + return false; | |
| 1077 | + } | |
| 1078 | + return jQuery( closestSection ).siblings( 'li.start_divider' ).length >= 1; | |
| 1079 | + } | |
| 1080 | + | |
| 1081 | + function getFieldsInRow( $row ) { | |
| 1082 | + return $row.children( 'li.form-field' ).not( '.ui-sortable-helper' ).not( '.edit_field_type_end_divider' ).filter( | |
| 1083 | + function() { | |
| 1084 | + return 'none' !== this.style.display; | |
| 1085 | + } | |
| 1086 | + ); | |
| 1087 | + } | |
| 1088 | + | |
| 1089 | + function determineIndexBasedOffOfMousePositionInRow( $row, x ) { | |
| 1090 | + var $inputs = getFieldsInRow( $row ), | |
| 1091 | + length = $inputs.length, | |
| 1092 | + index, input, inputLeft, returnIndex; | |
| 1093 | + | |
| 1094 | + returnIndex = 0; | |
| 1095 | + for ( index = length - 1; index >= 0; --index ) { | |
| 1096 | + input = $inputs.get( index ); | |
| 1097 | + inputLeft = jQuery( input ).offset().left; | |
| 1098 | + if ( x > inputLeft ) { | |
| 1099 | + returnIndex = index; | |
| 1100 | + if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) { | |
| 1101 | + returnIndex = index + 1; | |
| 1102 | + } | |
| 1103 | + break; | |
| 1104 | + } | |
| 1105 | + } | |
| 1106 | + | |
| 1107 | + return returnIndex; | |
| 1108 | + } | |
| 1109 | + | |
| 1110 | + function syncLayoutClasses( $item, type ) { | |
| 1111 | + var $fields, size, layoutClasses, classToAddFunction; | |
| 1112 | + | |
| 1113 | + if ( 'undefined' === typeof type ) { | |
| 1114 | + type = 'even'; | |
| 1115 | + } | |
| 1116 | + | |
| 1117 | + $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' ); | |
| 1118 | + size = $fields.length; | |
| 1119 | + layoutClasses = getLayoutClasses(); | |
| 1120 | + | |
| 1121 | + if ( 'even' === type && 5 !== size ) { | |
| 1122 | + $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) ); | |
| 1123 | + } else if ( 'clear' === type ) { | |
| 1124 | + $fields.each( getSyncLayoutClass( layoutClasses, '' ) ); | |
| 1125 | + } else { | |
| 1126 | + if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) { | |
| 1127 | + classToAddFunction = function( index ) { | |
| 1128 | + return getClassForBlock( size, type, index ); | |
| 1129 | + }; | |
| 1130 | + } else { | |
| 1131 | + classToAddFunction = function( index ) { | |
| 1132 | + var size = type[ index ]; | |
| 1133 | + return getLayoutClassForSize( size ); | |
| 1134 | + }; | |
| 1135 | + } | |
| 1136 | + | |
| 1137 | + $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) ); | |
| 1138 | + } | |
| 1139 | + | |
| 1140 | + updateFieldGroupControls( $item.parent(), $fields.length ); | |
| 1141 | + } | |
| 1142 | + | |
| 1143 | + function updateFieldGroupControls( $row, count ) { | |
| 1144 | + var rowOffset, shouldShowControls, controls; | |
| 1145 | + | |
| 1146 | + rowOffset = $row.offset(); | |
| 1147 | + | |
| 1148 | + if ( 'undefined' === typeof rowOffset ) { | |
| 1149 | + return; | |
| 1150 | + } | |
| 1151 | + | |
| 1152 | + shouldShowControls = count >= 2; | |
| 1153 | + | |
| 1154 | + controls = document.getElementById( 'frm_field_group_controls' ); | |
| 1155 | + if ( null === controls ) { | |
| 1156 | + if ( ! shouldShowControls ) { | |
| 1157 | + // exit early. if we do not need controls and they do not exist, do nothing. | |
| 1158 | + return; | |
| 1159 | + } | |
| 1160 | + | |
| 1161 | + controls = div(); | |
| 1162 | + controls.id = 'frm_field_group_controls'; | |
| 1163 | + controls.innerHTML = ''.concat( | |
| 1164 | + '<span><svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg></span>', | |
| 1165 | + '<span class="frm-move"><svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg></span>' | |
| 1166 | + ); | |
| 1167 | + document.getElementById( 'frm_builder_page' ).appendChild( controls ); | |
| 1168 | + } | |
| 1169 | + | |
| 1170 | + $row.append( controls ); | |
| 1171 | + controls.style.display = shouldShowControls ? 'block' : 'none'; | |
| 1172 | + } | |
| 1173 | + | |
| 1174 | + function getSyncLayoutClass( layoutClasses, classToAdd ) { | |
| 1175 | + return function( itemIndex ) { | |
| 1176 | + var currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput; | |
| 1177 | + | |
| 1178 | + currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd; | |
| 1179 | + length = layoutClasses.length; | |
| 1180 | + activeLayoutClass = false; | |
| 1181 | + for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) { | |
| 1182 | + currentClass = layoutClasses[ layoutClassIndex ]; | |
| 1183 | + if ( this.classList.contains( currentClass ) ) { | |
| 1184 | + activeLayoutClass = currentClass; | |
| 1185 | + break; | |
| 1186 | + } | |
| 1187 | + } | |
| 1188 | + | |
| 1189 | + fieldId = this.dataset.fid; | |
| 1190 | + | |
| 1191 | + if ( 'undefined' === typeof fieldId ) { | |
| 1192 | + // we are syncing the drag/drop placeholder before the actual field has loaded. | |
| 1193 | + // this will get called again afterward and the input will exist then. | |
| 1194 | + this.classList.add( currentClassToAdd ); | |
| 1195 | + return; | |
| 1196 | + } | |
| 1197 | + | |
| 1198 | + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) ); | |
| 1199 | + layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId ); | |
| 1200 | + | |
| 1201 | + if ( null === layoutClassesInput ) { | |
| 1202 | + // not every field type has a layout class input. | |
| 1203 | + return; | |
| 1204 | + } | |
| 1205 | + | |
| 1206 | + if ( false === activeLayoutClass ) { | |
| 1207 | + if ( '' !== currentClassToAdd ) { | |
| 1208 | + layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd ); | |
| 1209 | + } | |
| 1210 | + } else { | |
| 1211 | + this.classList.remove( activeLayoutClass ); | |
| 1212 | + layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd ); | |
| 1213 | + } | |
| 1214 | + | |
| 1215 | + if ( this.classList.contains( 'frm_first' ) ) { | |
| 1216 | + this.classList.remove( 'frm_first' ); | |
| 1217 | + layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim(); | |
| 1218 | + } | |
| 1219 | + | |
| 1220 | + if ( 0 === itemIndex ) { | |
| 1221 | + this.classList.add( 'frm_first' ); | |
| 1222 | + layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' ); | |
| 1223 | + } | |
| 1224 | + | |
| 1225 | + jQuery( layoutClassesInput ).trigger( 'change' ); | |
| 1226 | + }; | |
| 1227 | + } | |
| 1228 | + | |
| 1229 | + function getLayoutClasses() { | |
| 1230 | + 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' ]; | |
| 1231 | + } | |
| 1232 | + | |
| 1233 | + function setupFieldOptionSorting( sort ) { | |
| 1234 | + var opts = { | |
| 1235 | + items: '.frm_sortable_field_opts li', | |
| 1236 | + axis: 'y', | |
| 1237 | + opacity: 0.65, | |
| 1238 | + forcePlaceholderSize: false, | |
| 1239 | + handle: '.frm-drag', | |
| 1240 | + helper: function( e, li ) { | |
| 1241 | + copyHelper = li.clone().insertAfter( li ); | |
| 1242 | + return li.clone(); | |
| 1243 | + }, | |
| 1244 | + stop: function( e, ui ) { | |
| 1245 | + copyHelper && copyHelper.remove(); | |
| 1246 | + var fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' ); | |
| 1247 | + resetDisplayedOpts( fieldId ); | |
| 1248 | + } | |
| 1249 | + }; | |
| 1250 | + | |
| 1251 | + jQuery( sort ).sortable( opts ); | |
| 1252 | + } | |
| 1253 | + | |
| 1254 | + // Get the section where a field is dropped | |
| 1255 | + function getSectionForFieldPlacement( currentItem ) { | |
| 1256 | + var section = ''; | |
| 1257 | + if ( typeof currentItem !== 'undefined' ) { | |
| 1258 | + section = currentItem.closest( '.edit_field_type_divider' ); | |
| 1259 | + } | |
| 1260 | + | |
| 1261 | + return section; | |
| 1262 | + } | |
| 1263 | + | |
| 1264 | + // Get the form ID where a field is dropped | |
| 1265 | + function getFormIdForFieldPlacement( section ) { | |
| 1266 | + var formId = ''; | |
| 1267 | + | |
| 1268 | + if ( typeof section[0] !== 'undefined' ) { | |
| 1269 | + var sDivide = section.children( '.start_divider' ); | |
| 1270 | + sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide ); | |
| 1271 | + if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) { | |
| 1272 | + var fieldId = section.attr( 'data-fid' ); | |
| 1273 | + formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val(); | |
| 1274 | + } | |
| 1275 | + } | |
| 1276 | + | |
| 1277 | + if ( typeof formId === 'undefined' || formId === '' ) { | |
| 1278 | + formId = thisFormId; | |
| 1279 | + } | |
| 1280 | + | |
| 1281 | + return formId; | |
| 1282 | + } | |
| 1283 | + | |
| 1284 | + // Get the section ID where a field is dropped | |
| 1285 | + function getSectionIdForFieldPlacement( section ) { | |
| 1286 | + var sectionId = 0; | |
| 1287 | + if ( typeof section[0] !== 'undefined' ) { | |
| 1288 | + sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' ); | |
| 1289 | + } | |
| 1290 | + | |
| 1291 | + return sectionId; | |
| 1292 | + } | |
| 1293 | + | |
| 1294 | + /** | |
| 1295 | + * Update a field after it is dragged and dropped into, out of, or between sections | |
| 1296 | + * | |
| 1297 | + * @param {object} currentItem | |
| 1298 | + */ | |
| 1299 | + function updateFieldAfterMovingBetweenSections( currentItem ) { | |
| 1300 | + var fieldId, section, formId, sectionId; | |
| 1301 | + | |
| 1302 | + fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' ); | |
| 1303 | + section = getSectionForFieldPlacement( currentItem ); | |
| 1304 | + formId = getFormIdForFieldPlacement( section ); | |
| 1305 | + sectionId = getSectionIdForFieldPlacement( section ); | |
| 1306 | + | |
| 1307 | + if ( currentItem.parent().hasClass( 'start_divider' ) ) { | |
| 1308 | + wrapFieldLiInPlace( currentItem ); | |
| 1309 | + } | |
| 1310 | + | |
| 1311 | + jQuery.ajax({ | |
| 1312 | + type: 'POST', url: ajaxurl, | |
| 1313 | + data: { | |
| 1314 | + action: 'frm_update_field_after_move', | |
| 1315 | + form_id: formId, | |
| 1316 | + field: fieldId, | |
| 1317 | + section_id: sectionId, | |
| 1318 | + nonce: frmGlobal.nonce | |
| 1319 | + }, | |
| 1320 | + success: function() { | |
| 1321 | + toggleSectionHolder(); | |
| 1322 | + updateInSectionValue( fieldId, sectionId ); | |
| 1323 | + } | |
| 1324 | + }); | |
| 1325 | + } | |
| 1326 | + | |
| 1327 | + // Update the in_section field value | |
| 1328 | + function updateInSectionValue( fieldId, sectionId ) { | |
| 1329 | + document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId; | |
| 1330 | + } | |
| 1331 | + | |
| 1332 | + /** | |
| 1333 | + * Add a new field by dragging and dropping it from the Fields sidebar | |
| 1334 | + * | |
| 1335 | + * @param {object} selectedItem | |
| 1336 | + * @param {object} fieldButton | |
| 1337 | + * @param {object} opts | |
| 1338 | + */ | |
| 1339 | + function insertNewFieldByDragging( selectedItem, fieldButton ) { | |
| 1340 | + var fieldType, addBtn, sortableData, currentItem, insertAtIndex, section, formId, sectionId, loadingID, hasBreak, $placeholder; | |
| 1341 | + | |
| 1342 | + fieldType = fieldButton.attr( 'id' ); | |
| 1343 | + | |
| 1344 | + // We'll optimistically disable the button now. We'll re-enable if AJAX fails | |
| 1345 | + if ( 'summary' === fieldType ) { | |
| 1346 | + addBtn = fieldButton.children( '.frm_add_field' ); | |
| 1347 | + disableSummaryBtnBeforeAJAX( addBtn, fieldButton ); | |
| 1348 | + } | |
| 1349 | + | |
| 1350 | + sortableData = jQuery( selectedItem ).data().uiSortable; | |
| 1351 | + currentItem = sortableData.currentItem; | |
| 1352 | + insertAtIndex = determineIndexBasedOffOfMousePositionInRow( currentItem.parent(), currentItem.offset().left ); | |
| 1353 | + jQuery( getFieldsInRow( currentItem.parent() ).get( insertAtIndex ) ).before( currentItem ); | |
| 1354 | + section = getSectionForFieldPlacement( currentItem ); | |
| 1355 | + formId = getFormIdForFieldPlacement( section ); | |
| 1356 | + sectionId = getSectionIdForFieldPlacement( section ); | |
| 1357 | + | |
| 1358 | + loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId(); | |
| 1359 | + $placeholder = jQuery( '<li class="frm-wait frmbutton_loadingnow" id="' + loadingID + '" ></li>' ); | |
| 1360 | + currentItem.replaceWith( $placeholder ); | |
| 1361 | + | |
| 1362 | + syncLayoutClasses( $placeholder ); | |
| 1363 | + | |
| 1364 | + hasBreak = 0; | |
| 1365 | + if ( 'summary' === fieldType ) { | |
| 1366 | + // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break | |
| 1367 | + hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0; | |
| 1368 | + } | |
| 1369 | + | |
| 1370 | + jQuery.ajax({ | |
| 1371 | + type: 'POST', url: ajaxurl, | |
| 1372 | + data: { | |
| 1373 | + action: 'frm_insert_field', | |
| 1374 | + form_id: formId, | |
| 1375 | + field_type: fieldType, | |
| 1376 | + section_id: sectionId, | |
| 1377 | + nonce: frmGlobal.nonce, | |
| 1378 | + has_break: hasBreak | |
| 1379 | + }, | |
| 1380 | + success: function( msg ) { | |
| 1381 | + var $siblings, replaceWith; | |
| 1382 | + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' ); | |
| 1383 | + $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' ); | |
| 1384 | + if ( ! $siblings.length ) { | |
| 1385 | + // if dragging into a new row, we need to wrap the li first. | |
| 1386 | + replaceWith = wrapFieldLi( msg ); | |
| 1387 | + } else { | |
| 1388 | + replaceWith = msg; | |
| 1389 | + } | |
| 1390 | + $placeholder.replaceWith( replaceWith ); | |
| 1391 | + updateFieldOrder(); | |
| 1392 | + afterAddField( msg, false ); | |
| 1393 | + if ( $siblings.length ) { | |
| 1394 | + syncLayoutClasses( $siblings.first() ); | |
| 1395 | + } | |
| 1396 | + toggleSectionHolder(); | |
| 1397 | + }, | |
| 1398 | + error: function( jqXHR, textStatus, errorThrown ) { | |
| 1399 | + maybeReenableSummaryBtnAfterAJAX( fieldType, addBtn, fieldButton, errorThrown ); | |
| 1400 | + } | |
| 1401 | + }); | |
| 1402 | + } | |
| 1403 | + | |
| 1404 | + /** | |
| 1405 | + * Get a unique id that automatically increments with every function call. | |
| 1406 | + * Can be used for any UI that requires a unique id. | |
| 1407 | + * Not to be used in data. | |
| 1408 | + * | |
| 1409 | + * @returns {integer} | |
| 1410 | + */ | |
| 1411 | + function getAutoId() { | |
| 1412 | + return ++autoId; | |
| 1413 | + } | |
| 1414 | + | |
| 1415 | + // don't allow page break, embed form, or section inside section field | |
| 1416 | + // don't allow page breaks inside of field groups. | |
| 1417 | + // don't allow field groups with sections inside of sections. | |
| 1418 | + // don't allow field groups in field groups. | |
| 1419 | + // don't allow hidden fields inside of field groups but allow them in sections. | |
| 1420 | + function allowDrop( ui ) { | |
| 1421 | + var fieldsInRow, insideFieldGroup, insideSection, isNewField, isPageBreak, isFieldGroup, isSection; | |
| 1422 | + | |
| 1423 | + fieldsInRow = getFieldsInRow( ui.placeholder.parent() ); | |
| 1424 | + | |
| 1425 | + if ( ! groupCanFitAnotherField( fieldsInRow, ui.item ) ) { | |
| 1426 | + return false; | |
| 1427 | + } | |
| 1428 | + | |
| 1429 | + insideFieldGroup = fieldsInRow.length > 0; | |
| 1430 | + insideSection = ui.placeholder.closest( '.start_divider' ).length > 0; | |
| 1431 | + | |
| 1432 | + if ( ! insideSection && ! insideFieldGroup ) { | |
| 1433 | + return true; | |
| 1434 | + } | |
| 1435 | + | |
| 1436 | + if ( insideFieldGroup && ui.placeholder.siblings( '.edit_field_type_break, .edit_field_type_hidden' ).length ) { | |
| 1437 | + // never allow any field beside a page break or a hidden field. | |
| 1438 | + return false; | |
| 1439 | + } | |
| 1440 | + | |
| 1441 | + if ( insideSection && ui.placeholder.siblings().length > 1 && ui.placeholder.prev().hasClass( 'edit_field_type_end_divider' ) ) { | |
| 1442 | + return false; | |
| 1443 | + } | |
| 1444 | + | |
| 1445 | + isNewField = ui.item.hasClass( 'frmbutton' ); | |
| 1446 | + | |
| 1447 | + if ( isNewField ) { | |
| 1448 | + isPageBreak = ui.item.hasClass( 'frm_tbreak' ); | |
| 1449 | + | |
| 1450 | + if ( isPageBreak ) { | |
| 1451 | + // do not allow page break in both sections and field groups. | |
| 1452 | + return false; | |
| 1453 | + } | |
| 1454 | + | |
| 1455 | + if ( ui.item.hasClass( 'frm_thidden' ) && insideFieldGroup ) { | |
| 1456 | + // do not allow a hidden field in a field group. | |
| 1457 | + return false; | |
| 1458 | + } | |
| 1459 | + | |
| 1460 | + if ( ! insideSection ) { | |
| 1461 | + return true; | |
| 1462 | + } | |
| 1463 | + | |
| 1464 | + return ! ui.item.hasClass( 'frm_tform' ) && ! ui.item.hasClass( 'frm_tdivider' ) && ! ui.item.hasClass( 'frm_tdivider-repeat' ); | |
| 1465 | + } | |
| 1466 | + | |
| 1467 | + isPageBreak = ui.item.hasClass( 'edit_field_type_break' ); | |
| 1468 | + | |
| 1469 | + if ( isPageBreak ) { | |
| 1470 | + // do not allow page break in both sections and field groups. | |
| 1471 | + return false; | |
| 1472 | + } | |
| 1473 | + | |
| 1474 | + isFieldGroup = ui.item.find( 'ul.frm_sorting' ).length > 0; | |
| 1475 | + isSection = ui.item.hasClass( 'edit_field_type_divider' ); | |
| 1476 | + | |
| 1477 | + if ( insideSection && isSection ) { | |
| 1478 | + // but do not allow a section inside of a section. | |
| 1479 | + return false; | |
| 1480 | + } | |
| 1481 | + | |
| 1482 | + if ( isFieldGroup && insideFieldGroup ) { | |
| 1483 | + // allow a field group inside of a field group if it is being placed within a section above/below another field group. | |
| 1484 | + return insideSection && ui.placeholder.siblings( 'li.edit_field_type_end_divider' ).length > 0; | |
| 1485 | + } | |
| 1486 | + | |
| 1487 | + if ( insideFieldGroup && ui.item.hasClass( 'edit_field_type_hidden' ) ) { | |
| 1488 | + // do not allow a hidden field inside of a field group. | |
| 1489 | + return false; | |
| 1490 | + } | |
| 1491 | + | |
| 1492 | + if ( ! insideSection ) { | |
| 1493 | + return true; | |
| 1494 | + } | |
| 1495 | + | |
| 1496 | + if ( ui.item.find( '.edit_field_type_divider' ).length ) { | |
| 1497 | + // if we are dragging a field group with a section, do not allow it in section. | |
| 1498 | + return false; | |
| 1499 | + } | |
| 1500 | + | |
| 1501 | + // moving an existing field | |
| 1502 | + return ! ui.item.hasClass( 'edit_field_type_form' ) && ! isSection; | |
| 1503 | + } | |
| 1504 | + | |
| 1505 | + function groupCanFitAnotherField( fieldsInRow, $field ) { | |
| 1506 | + var fieldId; | |
| 1507 | + if ( fieldsInRow.length < 6 ) { | |
| 1508 | + return true; | |
| 1509 | + } | |
| 1510 | + if ( fieldsInRow.length > 6 ) { | |
| 1511 | + return false; | |
| 1512 | + } | |
| 1513 | + fieldId = $field.attr( 'data-fid' ); | |
| 1514 | + // allow 6 if we're not changing field groups. | |
| 1515 | + return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length; | |
| 1516 | + } | |
| 1517 | + | |
| 1518 | + function loadFields( fieldId ) { | |
| 1519 | + var addHtmlToField, nextElement, | |
| 1520 | + thisField = document.getElementById( fieldId ), | |
| 1521 | + $thisField = jQuery( thisField ), | |
| 1522 | + field = []; | |
| 1523 | + | |
| 1524 | + addHtmlToField = function( element ) { | |
| 1525 | + var frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' ); | |
| 1526 | + element.classList.add( 'frm_load_now' ); | |
| 1527 | + if ( frmHiddenFdata !== null ) { | |
| 1528 | + field.push( frmHiddenFdata.innerHTML ); | |
| 1529 | + } | |
| 1530 | + }; | |
| 1531 | + | |
| 1532 | + nextElement = thisField; | |
| 1533 | + addHtmlToField( nextElement ); | |
| 1534 | + while ( nextElement.nextElementSibling && field.length < 15 ) { | |
| 1535 | + addHtmlToField( nextElement.nextElementSibling ); | |
| 1536 | + nextElement = nextElement.nextElementSibling; | |
| 1537 | + } | |
| 1538 | + | |
| 1539 | + jQuery.ajax({ | |
| 1540 | + type: 'POST', url: ajaxurl, | |
| 1541 | + data: { | |
| 1542 | + action: 'frm_load_field', | |
| 1543 | + field: field, | |
| 1544 | + form_id: thisFormId, | |
| 1545 | + nonce: frmGlobal.nonce | |
| 1546 | + }, | |
| 1547 | + success: function( html ) { | |
| 1548 | + var key, $nextSet; | |
| 1549 | + | |
| 1550 | + html = html.replace( /^\s+|\s+$/g, '' ); | |
| 1551 | + if ( html.indexOf( '{' ) !== 0 ) { | |
| 1552 | + jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' ); | |
| 1553 | + return; | |
| 1554 | + } | |
| 1555 | + | |
| 1556 | + html = JSON.parse( html ); | |
| 1557 | + | |
| 1558 | + for ( key in html ) { | |
| 1559 | + jQuery( '#frm_field_id_' + key ).replaceWith( html[key]); | |
| 1560 | + setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' ); | |
| 1561 | + } | |
| 1562 | + | |
| 1563 | + $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' ); | |
| 1564 | + if ( $nextSet.length ) { | |
| 1565 | + loadFields( $nextSet.attr( 'id' ) ); | |
| 1566 | + } else { | |
| 1567 | + // go up a level | |
| 1568 | + $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' ); | |
| 1569 | + if ( $nextSet.length ) { | |
| 1570 | + loadFields( $nextSet.attr( 'id' ) ); | |
| 1571 | + } | |
| 1572 | + } | |
| 1573 | + | |
| 1574 | + initiateMultiselect(); | |
| 1575 | + renumberPageBreaks(); | |
| 1576 | + maybeHideQuantityProductFieldOption(); | |
| 1577 | + } | |
| 1578 | + }); | |
| 1579 | + } | |
| 1580 | + | |
| 1581 | + function addFieldClick() { | |
| 1582 | + /*jshint validthis:true */ | |
| 1583 | + var $thisObj = jQuery( this ); | |
| 1584 | + // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/ | |
| 1585 | + if ( $thisObj.hasClass( 'disabled' ) ) { | |
| 1586 | + return false; | |
| 1587 | + } | |
| 1588 | + | |
| 1589 | + var $button = $thisObj.closest( '.frmbutton' ); | |
| 1590 | + var fieldType = $button.attr( 'id' ); | |
| 1591 | + | |
| 1592 | + var hasBreak = 0; | |
| 1593 | + if ( 'summary' === fieldType ) { | |
| 1594 | + // We'll optimistically disable $button now. We'll re-enable if AJAX fails | |
| 1595 | + disableSummaryBtnBeforeAJAX( $thisObj, $button ); | |
| 1596 | + | |
| 1597 | + hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0; | |
| 1598 | + } | |
| 1599 | + | |
| 1600 | + var formId = thisFormId; | |
| 1601 | + | |
| 1602 | + jQuery.ajax({ | |
| 1603 | + type: 'POST', | |
| 1604 | + url: ajaxurl, | |
| 1605 | + data: { | |
| 1606 | + action: 'frm_insert_field', | |
| 1607 | + form_id: formId, | |
| 1608 | + field_type: fieldType, | |
| 1609 | + section_id: 0, | |
| 1610 | + nonce: frmGlobal.nonce, | |
| 1611 | + has_break: hasBreak | |
| 1612 | + }, | |
| 1613 | + success: function( msg ) { | |
| 1614 | + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' ); | |
| 1615 | + $newFields.append( wrapFieldLi( msg ) ); | |
| 1616 | + afterAddField( msg, true ); | |
| 1617 | + }, | |
| 1618 | + error: function( jqXHR, textStatus, errorThrown ) { | |
| 1619 | + maybeReenableSummaryBtnAfterAJAX( fieldType, $thisObj, $button, errorThrown ); | |
| 1620 | + } | |
| 1621 | + }); | |
| 1622 | + return false; | |
| 1623 | + } | |
| 1624 | + | |
| 1625 | + function disableSummaryBtnBeforeAJAX( addBtn, fieldButton ) { | |
| 1626 | + addBtn.addClass( 'disabled' ); | |
| 1627 | + fieldButton.draggable( 'disable' ); | |
| 1628 | + } | |
| 1629 | + | |
| 1630 | + function reenableAddSummaryBtn() { | |
| 1631 | + var frmBtn = jQuery( 'li#summary' ); | |
| 1632 | + var addFieldLink = frmBtn.children( '.frm_add_field' ); | |
| 1633 | + frmBtn.draggable( 'enable' ); | |
| 1634 | + addFieldLink.removeClass( 'disabled' ); | |
| 1635 | + } | |
| 1636 | + | |
| 1637 | + function maybeDisableAddSummaryBtn() { | |
| 1638 | + var summary = document.getElementById( 'summary' ); | |
| 1639 | + if ( summary && ! summary.classList.contains( 'frm_show_upgrade' ) && formHasSummaryField() ) { | |
| 1640 | + disableAddSummaryBtn(); | |
| 1641 | + } | |
| 1642 | + } | |
| 1643 | + | |
| 1644 | + function disableAddSummaryBtn() { | |
| 1645 | + var frmBtn = jQuery( 'li#summary' ); | |
| 1646 | + var addFieldLink = frmBtn.children( '.frm_add_field' ); | |
| 1647 | + frmBtn.draggable( 'disable' ); | |
| 1648 | + addFieldLink.addClass( 'disabled' ); | |
| 1649 | + } | |
| 1650 | + | |
| 1651 | + function maybeReenableSummaryBtnAfterAJAX( fieldType, addBtn, fieldButton, errorThrown ) { | |
| 1652 | + infoModal( errorThrown + '. Please try again.' ); | |
| 1653 | + if ( 'summary' === fieldType ) { | |
| 1654 | + addBtn.removeClass( 'disabled' ); | |
| 1655 | + fieldButton.draggable( 'enable' ); | |
| 1656 | + } | |
| 1657 | + } | |
| 1658 | + | |
| 1659 | + function formHasSummaryField() { | |
| 1660 | + // .edit_field_type_summary is a better selector here in order to also cover fields loaded by AJAX | |
| 1661 | + return $newFields.children( 'li.edit_field_type_summary' ).length > 0; | |
| 1662 | + } | |
| 1663 | + | |
| 1664 | + function maybeHideQuantityProductFieldOption() { | |
| 1665 | + var hide = true, | |
| 1666 | + opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' ); | |
| 1667 | + | |
| 1668 | + if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) { | |
| 1669 | + hide = false; | |
| 1670 | + } | |
| 1671 | + | |
| 1672 | + for ( var i = 0; i < opts.length; i++ ) { | |
| 1673 | + if ( hide ) { | |
| 1674 | + opts[ i ].classList.add( 'frm_hidden' ); | |
| 1675 | + } else { | |
| 1676 | + opts[ i ].classList.remove( 'frm_hidden' ); | |
| 1677 | + } | |
| 1678 | + } | |
| 1679 | + } | |
| 1680 | + | |
| 1681 | + function duplicateField() { | |
| 1682 | + var $field, fieldId, children; | |
| 1683 | + | |
| 1684 | + $field = jQuery( this ).closest( 'li.form-field' ); | |
| 1685 | + | |
| 1686 | + if ( $field.hasClass( 'frm-section-collapsed' ) || $field.hasClass( 'frm-page-collapsed' ) ) { | |
| 1687 | + return false; | |
| 1688 | + } | |
| 1689 | + | |
| 1690 | + closeOpenFieldDropdowns(); | |
| 1691 | + | |
| 1692 | + fieldId = $field.data( 'fid' ); | |
| 1693 | + children = fieldsInSection( fieldId ); | |
| 1694 | + | |
| 1695 | + jQuery.ajax({ | |
| 1696 | + type: 'POST', | |
| 1697 | + url: ajaxurl, | |
| 1698 | + data: { | |
| 1699 | + action: 'frm_duplicate_field', | |
| 1700 | + field_id: fieldId, | |
| 1701 | + form_id: thisFormId, | |
| 1702 | + children: children, | |
| 1703 | + nonce: frmGlobal.nonce | |
| 1704 | + }, | |
| 1705 | + success: function( msg ) { | |
| 1706 | + if ( $field.siblings( 'li.form-field' ).length ) { | |
| 1707 | + $field.after( msg ); | |
| 1708 | + syncLayoutClasses( $field ); | |
| 1709 | + } else { | |
| 1710 | + $field.parent().parent().after( wrapFieldLi( msg ) ); | |
| 1711 | + } | |
| 1712 | + updateFieldOrder(); | |
| 1713 | + afterAddField( msg, false ); | |
| 1714 | + } | |
| 1715 | + }); | |
| 1716 | + return false; | |
| 1717 | + } | |
| 1718 | + | |
| 1719 | + function closeOpenFieldDropdowns() { | |
| 1720 | + var openSettings = document.querySelector( '.frm-field-settings-open' ); | |
| 1721 | + if ( null !== openSettings ) { | |
| 1722 | + openSettings.classList.remove( 'frm-field-settings-open' ); | |
| 1723 | + jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings ); | |
| 1724 | + jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' ); | |
| 1725 | + } | |
| 1726 | + } | |
| 1727 | + | |
| 1728 | + function handleClickOutsideOfFieldSettings( event ) { | |
| 1729 | + if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) { | |
| 1730 | + closeOpenFieldDropdowns(); | |
| 1731 | + } | |
| 1732 | + } | |
| 1733 | + | |
| 1734 | + function checkForMultiselectKeysOnMouseMove( event ) { | |
| 1735 | + var keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey ); | |
| 1736 | + jQuery( document.getElementById( 'frm_builder_page' ) ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown ); | |
| 1737 | + checkForActiveHoverTarget( event ); | |
| 1738 | + } | |
| 1739 | + | |
| 1740 | + function checkForActiveHoverTarget( event ) { | |
| 1741 | + var container, elementFromPoint, list, previousHoverTarget; | |
| 1742 | + | |
| 1743 | + container = document.getElementById( 'post-body-content' ); | |
| 1744 | + if ( container.classList.contains( 'frm-dragging-field' ) ) { | |
| 1745 | + return; | |
| 1746 | + } | |
| 1747 | + | |
| 1748 | + if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) { | |
| 1749 | + // do not set a hover target if a dropdown is open for the current hover target. | |
| 1750 | + return; | |
| 1751 | + } | |
| 1752 | + | |
| 1753 | + elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 1754 | + if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) { | |
| 1755 | + | |
| 1756 | + list = elementFromPoint.closest( 'ul.frm_sorting' ); | |
| 1757 | + | |
| 1758 | + if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) { | |
| 1759 | + previousHoverTarget = maybeRemoveGroupHoverTarget(); | |
| 1760 | + if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) { | |
| 1761 | + destroyFieldGroupPopup(); | |
| 1762 | + } | |
| 1763 | + updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length ); | |
| 1764 | + list.classList.add( 'frm-field-group-hover-target' ); | |
| 1765 | + jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove ); | |
| 1766 | + } | |
| 1767 | + } | |
| 1768 | + } | |
| 1769 | + | |
| 1770 | + function maybeRemoveGroupHoverTarget() { | |
| 1771 | + var controls, previousHoverTarget; | |
| 1772 | + | |
| 1773 | + controls = document.getElementById( 'frm_field_group_controls' ); | |
| 1774 | + if ( null !== controls ) { | |
| 1775 | + controls.style.display = 'none'; | |
| 1776 | + } | |
| 1777 | + | |
| 1778 | + previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 1779 | + if ( null === previousHoverTarget ) { | |
| 1780 | + return false; | |
| 1781 | + } | |
| 1782 | + | |
| 1783 | + jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove ); | |
| 1784 | + previousHoverTarget.classList.remove( 'frm-field-group-hover-target' ); | |
| 1785 | + return previousHoverTarget; | |
| 1786 | + } | |
| 1787 | + | |
| 1788 | + function maybeRemoveHoverTargetOnMouseMove( event ) { | |
| 1789 | + var elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 1790 | + if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) { | |
| 1791 | + return; | |
| 1792 | + } | |
| 1793 | + maybeRemoveGroupHoverTarget(); | |
| 1794 | + } | |
| 1795 | + | |
| 1796 | + function onFieldActionDropdownShow() { | |
| 1797 | + unselectFieldGroups(); | |
| 1798 | + // maybe offset the dropdown if it goes off of the right of the screen. | |
| 1799 | + setTimeout( | |
| 1800 | + function() { | |
| 1801 | + var ul, $ul; | |
| 1802 | + ul = document.querySelector( '.dropdown.open ul' ); | |
| 1803 | + if ( null === ul ) { | |
| 1804 | + return; | |
| 1805 | + } | |
| 1806 | + $ul = jQuery( ul ); | |
| 1807 | + if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) { | |
| 1808 | + ul.style.left = ( -$ul.outerWidth() ) + 'px'; | |
| 1809 | + } | |
| 1810 | + }, | |
| 1811 | + 0 | |
| 1812 | + ); | |
| 1813 | + } | |
| 1814 | + | |
| 1815 | + function wrapFieldLi( li ) { | |
| 1816 | + return jQuery( '<li>' ) | |
| 1817 | + .addClass( 'frm_field_box' ) | |
| 1818 | + .html( | |
| 1819 | + jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li ) | |
| 1820 | + ); | |
| 1821 | + } | |
| 1822 | + | |
| 1823 | + function wrapFieldLiInPlace( li ) { | |
| 1824 | + jQuery( li ).wrap( '<li class="frm_field_box"><ul class="frm_grid_container frm_sorting"></ul></li>' ); | |
| 1825 | + } | |
| 1826 | + | |
| 1827 | + function afterAddField( msg, addFocus ) { | |
| 1828 | + var regex = /id="(\S+)"/, | |
| 1829 | + match = regex.exec( msg ), | |
| 1830 | + field = document.getElementById( match[1]), | |
| 1831 | + section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider', | |
| 1832 | + $thisSection = jQuery( section ), | |
| 1833 | + type = field.getAttribute( 'data-type' ), | |
| 1834 | + toggled = false, | |
| 1835 | + $parentSection; | |
| 1836 | + | |
| 1837 | + setupSortable( section ); | |
| 1838 | + | |
| 1839 | + if ( 'quantity' === type ) { | |
| 1840 | + // try to automatically attach a product field | |
| 1841 | + maybeSetProductField( field ); | |
| 1842 | + } | |
| 1843 | + | |
| 1844 | + if ( 'product' === type || 'quantity' === type ) { | |
| 1845 | + // quantity too needs to be a part of the if stmt especially cos of the very | |
| 1846 | + // 1st quantity field (or even if it's just one quantity field in the form). | |
| 1847 | + maybeHideQuantityProductFieldOption(); | |
| 1848 | + } | |
| 1849 | + | |
| 1850 | + if ( $thisSection.length ) { | |
| 1851 | + $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' ); | |
| 1852 | + } else { | |
| 1853 | + $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' ); | |
| 1854 | + if ( $parentSection.length ) { | |
| 1855 | + toggleOneSectionHolder( $parentSection ); | |
| 1856 | + toggled = true; | |
| 1857 | + } | |
| 1858 | + } | |
| 1859 | + | |
| 1860 | + if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) { | |
| 1861 | + renumberPageBreaks(); | |
| 1862 | + } | |
| 1863 | + | |
| 1864 | + addClass( field, 'frm-newly-added' ); | |
| 1865 | + setTimeout( function() { | |
| 1866 | + field.classList.remove( 'frm-newly-added' ); | |
| 1867 | + }, 1000 ); | |
| 1868 | + | |
| 1869 | + if ( addFocus ) { | |
| 1870 | + var bounding = field.getBoundingClientRect(), | |
| 1871 | + container = document.getElementById( 'post-body-content' ), | |
| 1872 | + inView = ( bounding.top >= 0 && | |
| 1873 | + bounding.left >= 0 && | |
| 1874 | + bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) && | |
| 1875 | + bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight ) | |
| 1876 | + ); | |
| 1877 | + | |
| 1878 | + if ( ! inView ) { | |
| 1879 | + container.scroll({ | |
| 1880 | + top: container.scrollHeight, | |
| 1881 | + left: 0, | |
| 1882 | + behavior: 'smooth' | |
| 1883 | + }); | |
| 1884 | + } | |
| 1885 | + | |
| 1886 | + if ( toggled === false ) { | |
| 1887 | + toggleOneSectionHolder( $thisSection ); | |
| 1888 | + } | |
| 1889 | + } | |
| 1890 | + | |
| 1891 | + deselectFields(); | |
| 1892 | + initiateMultiselect(); | |
| 1893 | + } | |
| 1894 | + | |
| 1895 | + function clearSettingsBox( preventFieldGroups ) { | |
| 1896 | + jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' ); | |
| 1897 | + jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' ); | |
| 1898 | + deselectFields( preventFieldGroups ); | |
| 1899 | + } | |
| 1900 | + | |
| 1901 | + function deselectFields( preventFieldGroups ) { | |
| 1902 | + jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' ); | |
| 1903 | + if ( ! preventFieldGroups ) { | |
| 1904 | + unselectFieldGroups(); | |
| 1905 | + } | |
| 1906 | + } | |
| 1907 | + | |
| 1908 | + function scrollToField( field ) { | |
| 1909 | + var newPos = field.getBoundingClientRect().top, | |
| 1910 | + container = document.getElementById( 'post-body-content' ); | |
| 1911 | + | |
| 1912 | + if ( typeof animate === 'undefined' ) { | |
| 1913 | + jQuery( container ).scrollTop( newPos ); | |
| 1914 | + } else { | |
| 1915 | + // TODO: smooth scroll | |
| 1916 | + jQuery( container ).animate({ scrollTop: newPos }, 500 ); | |
| 1917 | + } | |
| 1918 | + } | |
| 1919 | + | |
| 1920 | + function checkCalculationCreatedByUser() { | |
| 1921 | + var calculation = this.value; | |
| 1922 | + var warningMessage = checkMatchingParens( calculation ); | |
| 1923 | + warningMessage += checkShortcodes( calculation, this ); | |
| 1924 | + | |
| 1925 | + if ( warningMessage !== '' ) { | |
| 1926 | + infoModal( calculation + '\n\n' + warningMessage ); | |
| 1927 | + } | |
| 1928 | + } | |
| 1929 | + | |
| 1930 | + /** | |
| 1931 | + * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is. | |
| 1932 | + */ | |
| 1933 | + function checkDetailPageSlug() { | |
| 1934 | + var slug = jQuery( '#param' ).val(), | |
| 1935 | + msg; | |
| 1936 | + slug = slug.trim().toLowerCase(); | |
| 1937 | + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( slug ) ) { | |
| 1938 | + msg = frm_admin_js.slug_is_reserved; | |
| 1939 | + msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) ); | |
| 1940 | + msg += '<br /><br />'; | |
| 1941 | + msg += addHtmlTags( '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>', 'div' ); | |
| 1942 | + infoModal( msg ); | |
| 1943 | + } | |
| 1944 | + } | |
| 1945 | + | |
| 1946 | + /** | |
| 1947 | + * Checks View filter value for params named with reserved words and displays a message if any are found. | |
| 1948 | + */ | |
| 1949 | + function checkFilterParamNames() { | |
| 1950 | + var regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig, | |
| 1951 | + filterValue = jQuery( this ).val(), | |
| 1952 | + match = regEx.exec( filterValue ), | |
| 1953 | + unsafeParams = ''; | |
| 1954 | + | |
| 1955 | + while ( match !== null ) { | |
| 1956 | + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( match[1]) ) { | |
| 1957 | + if ( unsafeParams !== '' ) { | |
| 1958 | + unsafeParams += '", "' + match[ 1 ]; | |
| 1959 | + } else { | |
| 1960 | + unsafeParams = match[ 1 ]; | |
| 1961 | + } | |
| 1962 | + } | |
| 1963 | + match = regEx.exec( filterValue ); | |
| 1964 | + } | |
| 1965 | + | |
| 1966 | + if ( unsafeParams !== '' ) { | |
| 1967 | + msg = frm_admin_js.param_is_reserved; | |
| 1968 | + msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) ); | |
| 1969 | + msg += '<br /><br />'; | |
| 1970 | + msg += ' <a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>'; | |
| 1971 | + | |
| 1972 | + infoModal( msg ); | |
| 1973 | + } | |
| 1974 | + } | |
| 1975 | + | |
| 1976 | + function addHtmlTags( text, tag ) { | |
| 1977 | + tag = tag ? tag : 'p'; | |
| 1978 | + return '<' + tag + '>' + text + '</' + tag + '>'; | |
| 1979 | + } | |
| 1980 | + | |
| 1981 | + /** | |
| 1982 | + * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found. | |
| 1983 | + * @param formula | |
| 1984 | + * @returns {string} | |
| 1985 | + */ | |
| 1986 | + function checkMatchingParens( formula ) { | |
| 1987 | + | |
| 1988 | + var stack = [], | |
| 1989 | + formulaArray = formula.split( '' ), | |
| 1990 | + length = formulaArray.length, | |
| 1991 | + opening = [ '{', '[', '(' ], | |
| 1992 | + closing = { | |
| 1993 | + '}': '{', | |
| 1994 | + ')': '(', | |
| 1995 | + ']': '[' | |
| 1996 | + }, | |
| 1997 | + unmatchedClosing = [], | |
| 1998 | + msg = '', | |
| 1999 | + i, top; | |
| 2000 | + | |
| 2001 | + for ( i = 0; i < length; i++ ) { | |
| 2002 | + if ( opening.includes( formulaArray[i]) ) { | |
| 2003 | + stack.push( formulaArray[i]); | |
| 2004 | + continue; | |
| 2005 | + } | |
| 2006 | + if ( closing.hasOwnProperty( formulaArray[i]) ) { | |
| 2007 | + top = stack.pop(); | |
| 2008 | + if ( top !== closing[formulaArray[i]]) { | |
| 2009 | + unmatchedClosing.push( formulaArray[i]); | |
| 2010 | + } | |
| 2011 | + } | |
| 2012 | + } | |
| 2013 | + | |
| 2014 | + if ( stack.length > 0 || unmatchedClosing.length > 0 ) { | |
| 2015 | + msg = frm_admin_js.unmatched_parens + '\n\n'; | |
| 2016 | + return msg; | |
| 2017 | + } | |
| 2018 | + | |
| 2019 | + return ''; | |
| 2020 | + } | |
| 2021 | + | |
| 2022 | + /** | |
| 2023 | + * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found. | |
| 2024 | + * @param calculation | |
| 2025 | + * @param inputElement | |
| 2026 | + * @returns {string} | |
| 2027 | + */ | |
| 2028 | + function checkShortcodes( calculation, inputElement ) { | |
| 2029 | + var msg = checkNonNumericShortcodes( calculation, inputElement ); | |
| 2030 | + msg += checkNonFormShortcodes( calculation ); | |
| 2031 | + | |
| 2032 | + return msg; | |
| 2033 | + } | |
| 2034 | + | |
| 2035 | + /** | |
| 2036 | + * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found. | |
| 2037 | + * @param calculation | |
| 2038 | + * | |
| 2039 | + * @param inputElement | |
| 2040 | + * @returns {string} | |
| 2041 | + */ | |
| 2042 | + function checkNonNumericShortcodes( calculation, inputElement ) { | |
| 2043 | + | |
| 2044 | + var msg = ''; | |
| 2045 | + | |
| 2046 | + if ( isTextCalculation( inputElement ) ) { | |
| 2047 | + return msg; | |
| 2048 | + } | |
| 2049 | + | |
| 2050 | + var nonNumericShortcodes = getNonNumericShortcodes(); | |
| 2051 | + | |
| 2052 | + if ( nonNumericShortcodes.test( calculation ) ) { | |
| 2053 | + msg = frm_admin_js.text_shortcodes + '\n\n'; | |
| 2054 | + } | |
| 2055 | + | |
| 2056 | + return msg; | |
| 2057 | + } | |
| 2058 | + | |
| 2059 | + /** | |
| 2060 | + * Determines if the calculation input is from a text calculation. | |
| 2061 | + * | |
| 2062 | + * @param inputElement | |
| 2063 | + */ | |
| 2064 | + function isTextCalculation( inputElement ) { | |
| 2065 | + return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' ); | |
| 2066 | + } | |
| 2067 | + | |
| 2068 | + /** | |
| 2069 | + * Returns a regular expression of shortcodes that can't be used in numeric calculations. | |
| 2070 | + * @returns {RegExp} | |
| 2071 | + */ | |
| 2072 | + function getNonNumericShortcodes() { | |
| 2073 | + return /\[(date|time|email|ip)\]/; | |
| 2074 | + } | |
| 2075 | + | |
| 2076 | + /** | |
| 2077 | + * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found. | |
| 2078 | + * @param formula | |
| 2079 | + * @returns {string} | |
| 2080 | + */ | |
| 2081 | + function checkNonFormShortcodes( formula ) { | |
| 2082 | + var nonFormShortcodes = getNonFormShortcodes(), | |
| 2083 | + msg = ''; | |
| 2084 | + | |
| 2085 | + if ( nonFormShortcodes.test( formula ) ) { | |
| 2086 | + msg += frm_admin_js.view_shortcodes + '\n\n'; | |
| 2087 | + } | |
| 2088 | + | |
| 2089 | + return msg; | |
| 2090 | + } | |
| 2091 | + | |
| 2092 | + /** | |
| 2093 | + * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email | |
| 2094 | + * Notifications, and other Formidable areas. | |
| 2095 | + * | |
| 2096 | + * @returns {RegExp} | |
| 2097 | + */ | |
| 2098 | + function getNonFormShortcodes() { | |
| 2099 | + return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g; | |
| 2100 | + } | |
| 2101 | + | |
| 2102 | + function isCalcBoxType( box, listClass ) { | |
| 2103 | + var list = jQuery( box ).find( '.frm_code_list' ); | |
| 2104 | + return 1 === list.length && list.hasClass( listClass ); | |
| 2105 | + } | |
| 2106 | + | |
| 2107 | + function extractExcludedOptions( exclude ) { | |
| 2108 | + var opts = []; | |
| 2109 | + if ( ! Array.isArray( exclude ) ) { | |
| 2110 | + return opts; | |
| 2111 | + } | |
| 2112 | + | |
| 2113 | + for ( var i = 0; i < exclude.length; i++ ) { | |
| 2114 | + if ( exclude[ i ].startsWith( '[' ) ) { | |
| 2115 | + opts.push( exclude[ i ]); | |
| 2116 | + // remove it | |
| 2117 | + exclude.splice( i, 1 ); | |
| 2118 | + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value | |
| 2119 | + i--; | |
| 2120 | + } | |
| 2121 | + } | |
| 2122 | + | |
| 2123 | + return opts; | |
| 2124 | + } | |
| 2125 | + | |
| 2126 | + function hasExcludedOption( field, excludedOpts ) { | |
| 2127 | + var hasOption = false; | |
| 2128 | + for ( var i = 0; i < excludedOpts.length; i++ ) { | |
| 2129 | + var inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) ); | |
| 2130 | + // 2nd condition checks that there's at least one non-empty value | |
| 2131 | + if ( inputs.length && jQuery( inputs[0]).val() ) { | |
| 2132 | + hasOption = true; | |
| 2133 | + break; | |
| 2134 | + } | |
| 2135 | + } | |
| 2136 | + return hasOption; | |
| 2137 | + } | |
| 2138 | + | |
| 2139 | + function getFieldOptionInputName( opt, fieldId ) { | |
| 2140 | + var at = opt.indexOf( ']' ); | |
| 2141 | + return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at ); | |
| 2142 | + } | |
| 2143 | + | |
| 2144 | + function popCalcFields( v, force ) { | |
| 2145 | + var box, exclude, fields, i, list, | |
| 2146 | + p = jQuery( v ).closest( '.frm-single-settings' ), | |
| 2147 | + calc = p.find( '.frm-calc-field' ); | |
| 2148 | + | |
| 2149 | + if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) { | |
| 2150 | + return; | |
| 2151 | + } | |
| 2152 | + | |
| 2153 | + var isSummary = isCalcBoxType( v, 'frm_js_summary_list' ); | |
| 2154 | + | |
| 2155 | + var fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val(); | |
| 2156 | + | |
| 2157 | + if ( force ) { | |
| 2158 | + box = v; | |
| 2159 | + } else { | |
| 2160 | + box = document.getElementById( 'frm-calc-box-' + fieldId ); | |
| 2161 | + } | |
| 2162 | + | |
| 2163 | + exclude = getExcludeArray( box, isSummary ); | |
| 2164 | + var excludedOpts = extractExcludedOptions( exclude ); | |
| 2165 | + | |
| 2166 | + fields = getFieldList(); | |
| 2167 | + list = document.getElementById( 'frm-calc-list-' + fieldId ); | |
| 2168 | + list.innerHTML = ''; | |
| 2169 | + | |
| 2170 | + for ( i = 0; i < fields.length; i++ ) { | |
| 2171 | + if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) || | |
| 2172 | + ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) { | |
| 2173 | + continue; | |
| 2174 | + } | |
| 2175 | + | |
| 2176 | + var span = document.createElement( 'span' ); | |
| 2177 | + span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) ); | |
| 2178 | + | |
| 2179 | + var a = document.createElement( 'a' ); | |
| 2180 | + a.setAttribute( 'href', '#' ); | |
| 2181 | + a.setAttribute( 'data-code', fields[i].fieldId ); | |
| 2182 | + a.classList.add( 'frm_insert_code' ); | |
| 2183 | + a.appendChild( span ); | |
| 2184 | + a.appendChild( document.createTextNode( fields[i].fieldName ) ); | |
| 2185 | + | |
| 2186 | + var li = document.createElement( 'li' ); | |
| 2187 | + li.classList.add( 'frm-field-list-' + fieldId ); | |
| 2188 | + li.classList.add( 'frm-field-list-' + fields[i].fieldType ); | |
| 2189 | + li.appendChild( a ); | |
| 2190 | + list.appendChild( li ); | |
| 2191 | + } | |
| 2192 | + } | |
| 2193 | + | |
| 2194 | + function getExcludeArray( calcBox, isSummary ) { | |
| 2195 | + var exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) ); | |
| 2196 | + | |
| 2197 | + if ( isSummary ) { | |
| 2198 | + // includedExtras are those that are normally excluded from the summary but the form owner can choose to include, | |
| 2199 | + // when they have been chosen to be included, then they can now be manually excluded in the calc box. | |
| 2200 | + var includedExtras = getIncludedExtras(); | |
| 2201 | + if ( includedExtras.length ) { | |
| 2202 | + for ( var i = 0; i < exclude.length; i++ ) { | |
| 2203 | + if ( includedExtras.includes( exclude[ i ]) ) { | |
| 2204 | + // remove it | |
| 2205 | + exclude.splice( i, 1 ); | |
| 2206 | + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value | |
| 2207 | + i--; | |
| 2208 | + } | |
| 2209 | + } | |
| 2210 | + } | |
| 2211 | + } | |
| 2212 | + | |
| 2213 | + return exclude; | |
| 2214 | + } | |
| 2215 | + | |
| 2216 | + function getIncludedExtras() { | |
| 2217 | + var checked = []; | |
| 2218 | + var checkboxes = document.getElementsByClassName( 'frm_include_extras_field' ); | |
| 2219 | + | |
| 2220 | + for ( var i = 0; i < checkboxes.length; i++ ) { | |
| 2221 | + if ( checkboxes[i].checked ) { | |
| 2222 | + checked.push( checkboxes[i].value ); | |
| 2223 | + } | |
| 2224 | + } | |
| 2225 | + | |
| 2226 | + return checked; | |
| 2227 | + } | |
| 2228 | + | |
| 2229 | + function rePopCalcFieldsForSummary() { | |
| 2230 | + popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true ); | |
| 2231 | + } | |
| 2232 | + | |
| 2233 | + function getFieldList( fieldType ) { | |
| 2234 | + var i, | |
| 2235 | + fields = [], | |
| 2236 | + allFields = document.querySelectorAll( 'li.frm_field_box' ), | |
| 2237 | + checkType = 'undefined' !== typeof fieldType; | |
| 2238 | + | |
| 2239 | + for ( i = 0; i < allFields.length; i++ ) { | |
| 2240 | + // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet | |
| 2241 | + if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) { | |
| 2242 | + continue; | |
| 2243 | + } | |
| 2244 | + | |
| 2245 | + var fieldId = allFields[ i ].getAttribute( 'data-fid' ); | |
| 2246 | + if ( typeof fieldId !== 'undefined' && fieldId ) { | |
| 2247 | + fields.push({ | |
| 2248 | + 'fieldId': fieldId, | |
| 2249 | + 'fieldName': getPossibleValue( 'frm_name_' + fieldId ), | |
| 2250 | + 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ), | |
| 2251 | + 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId ) | |
| 2252 | + }); | |
| 2253 | + } | |
| 2254 | + } | |
| 2255 | + | |
| 2256 | + return fields; | |
| 2257 | + } | |
| 2258 | + | |
| 2259 | + function popProductFields( field ) { | |
| 2260 | + var i, checked, id, | |
| 2261 | + options = [], | |
| 2262 | + current = getCurrentProductFields( field ), | |
| 2263 | + fName = field.getAttribute( 'data-frmfname' ), | |
| 2264 | + products = getFieldList( 'product' ), | |
| 2265 | + quantities = getFieldList( 'quantity' ), | |
| 2266 | + isSelect = field.tagName === 'SELECT', // for reverse compatibility. | |
| 2267 | + // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former | |
| 2268 | + auto = 1 === quantities.length && 1 === products.length; | |
| 2269 | + | |
| 2270 | + if ( isSelect ) { | |
| 2271 | + // This fallback can be removed after 4.05. | |
| 2272 | + current = field.getAttribute( 'data-frmcurrent' ); | |
| 2273 | + } | |
| 2274 | + | |
| 2275 | + for ( i = 0 ; i < products.length ; i++ ) { | |
| 2276 | + // let's be double sure it's string, else indexOf will fail | |
| 2277 | + id = products[ i ].fieldId.toString(); | |
| 2278 | + checked = auto || -1 !== current.indexOf( id ); | |
| 2279 | + if ( isSelect ) { | |
| 2280 | + // This fallback can be removed after 4.05. | |
| 2281 | + checked = checked ? ' selected' : ''; | |
| 2282 | + options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' ); | |
| 2283 | + } else { | |
| 2284 | + checked = checked ? ' checked' : ''; | |
| 2285 | + options.push( '<label class="frm6">' ); | |
| 2286 | + options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName ); | |
| 2287 | + options.push( '</label>' ); | |
| 2288 | + } | |
| 2289 | + } | |
| 2290 | + | |
| 2291 | + field.innerHTML = options.join( '' ); | |
| 2292 | + } | |
| 2293 | + | |
| 2294 | + function getCurrentProductFields( prodFieldOpt ) { | |
| 2295 | + var products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ), | |
| 2296 | + idsArray = []; | |
| 2297 | + | |
| 2298 | + for ( var i = 0; i < products.length; i++ ) { | |
| 2299 | + idsArray.push( products[ i ].value ); | |
| 2300 | + } | |
| 2301 | + | |
| 2302 | + return idsArray; | |
| 2303 | + } | |
| 2304 | + | |
| 2305 | + function popAllProductFields() { | |
| 2306 | + var opts = document.querySelectorAll( '.frmjs_prod_field_opt' ); | |
| 2307 | + for ( var i = 0; i < opts.length; i++ ) { | |
| 2308 | + popProductFields( opts[ i ]); | |
| 2309 | + } | |
| 2310 | + } | |
| 2311 | + | |
| 2312 | + function maybeSetProductField( field ) { | |
| 2313 | + var fieldId = field.getAttribute( 'data-fid' ), | |
| 2314 | + productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' ); | |
| 2315 | + | |
| 2316 | + if ( null === productFieldOpt ) { | |
| 2317 | + return; | |
| 2318 | + } | |
| 2319 | + | |
| 2320 | + popProductFields( productFieldOpt ); | |
| 2321 | + // in order to move its settings to that LHS panel where | |
| 2322 | + // the update form resides, else it'll lose this setting | |
| 2323 | + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) ); | |
| 2324 | + } | |
| 2325 | + | |
| 2326 | + /** | |
| 2327 | + * If the element doesn't exist, use a blank value. | |
| 2328 | + */ | |
| 2329 | + function getPossibleValue( id ) { | |
| 2330 | + field = document.getElementById( id ); | |
| 2331 | + if ( field !== null ) { | |
| 2332 | + return field.value; | |
| 2333 | + } else { | |
| 2334 | + return ''; | |
| 2335 | + } | |
| 2336 | + } | |
| 2337 | + | |
| 2338 | + function liveChanges() { | |
| 2339 | + /*jshint validthis:true */ | |
| 2340 | + var option, | |
| 2341 | + newValue = this.value, | |
| 2342 | + changes = document.getElementById( this.getAttribute( 'data-changeme' ) ), | |
| 2343 | + att = this.getAttribute( 'data-changeatt' ); | |
| 2344 | + | |
| 2345 | + if ( changes === null ) { | |
| 2346 | + return; | |
| 2347 | + } | |
| 2348 | + | |
| 2349 | + if ( att !== null ) { | |
| 2350 | + if ( changes.tagName === 'SELECT' && att === 'placeholder' ) { | |
| 2351 | + option = changes.options[0]; | |
| 2352 | + if ( option.value === '' ) { | |
| 2353 | + option.innerHTML = newValue; | |
| 2354 | + } else { | |
| 2355 | + // Create a placeholder option if there are no blank values. | |
| 2356 | + addBlankSelectOption( changes, newValue ); | |
| 2357 | + } | |
| 2358 | + } else if ( att === 'class' ) { | |
| 2359 | + changeFieldClass( changes, this ); | |
| 2360 | + } else { | |
| 2361 | + changes.setAttribute( att, newValue ); | |
| 2362 | + } | |
| 2363 | + } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) { | |
| 2364 | + if ( newValue !== '' ) { | |
| 2365 | + changes.innerHTML = '<input type="text" value="" disabled />'; | |
| 2366 | + } | |
| 2367 | + } else { | |
| 2368 | + changes.innerHTML = newValue; | |
| 2369 | + } | |
| 2370 | + } | |
| 2371 | + | |
| 2372 | + function toggleInvalidMsg() { | |
| 2373 | + /*jshint validthis:true */ | |
| 2374 | + var typeDropdown, fieldType, | |
| 2375 | + fieldId = this.id.replace( 'frm_format_', '' ), | |
| 2376 | + hasValue = this.value !== ''; | |
| 2377 | + | |
| 2378 | + typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0]; | |
| 2379 | + fieldType = typeDropdown.options[typeDropdown.selectedIndex].value; | |
| 2380 | + | |
| 2381 | + if ( fieldType === 'text' ) { | |
| 2382 | + toggleValidationBox( hasValue, '.frm_invalid_msg' + fieldId ); | |
| 2383 | + } | |
| 2384 | + } | |
| 2385 | + | |
| 2386 | + function markRequired() { | |
| 2387 | + /*jshint validthis:true */ | |
| 2388 | + var thisid = this.id.replace( 'frm_', '' ), | |
| 2389 | + fieldId = thisid.replace( 'req_field_', '' ), | |
| 2390 | + checked = this.checked, | |
| 2391 | + label = jQuery( '#field_label_' + fieldId + ' .frm_required' ); | |
| 2392 | + | |
| 2393 | + toggleValidationBox( checked, '.frm_required_details' + fieldId ); | |
| 2394 | + | |
| 2395 | + if ( checked ) { | |
| 2396 | + var $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' ); | |
| 2397 | + if ( $reqBox.val() === '' ) { | |
| 2398 | + $reqBox.val( '*' ); | |
| 2399 | + } | |
| 2400 | + label.removeClass( 'frm_hidden' ); | |
| 2401 | + } else { | |
| 2402 | + label.addClass( 'frm_hidden' ); | |
| 2403 | + } | |
| 2404 | + } | |
| 2405 | + | |
| 2406 | + function toggleValidationBox( hasValue, messageClass ) { | |
| 2407 | + $msg = jQuery( messageClass ); | |
| 2408 | + if ( hasValue ) { | |
| 2409 | + $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' ); | |
| 2410 | + } else { | |
| 2411 | + //Fade out validation options | |
| 2412 | + var v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length; | |
| 2413 | + if ( v === 0 ) { | |
| 2414 | + $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' ); | |
| 2415 | + } | |
| 2416 | + } | |
| 2417 | + } | |
| 2418 | + | |
| 2419 | + function markUnique() { | |
| 2420 | + /*jshint validthis:true */ | |
| 2421 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 2422 | + var $thisField = jQuery( '.frm_unique_details' + fieldId ); | |
| 2423 | + if ( this.checked ) { | |
| 2424 | + $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' ); | |
| 2425 | + $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' ); | |
| 2426 | + if ( $unqDetail.val() === '' ) { | |
| 2427 | + $unqDetail.val( frm_admin_js.default_unique ); | |
| 2428 | + } | |
| 2429 | + } else { | |
| 2430 | + var v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length; | |
| 2431 | + if ( v === 0 ) { | |
| 2432 | + $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' ); | |
| 2433 | + } | |
| 2434 | + } | |
| 2435 | + } | |
| 2436 | + | |
| 2437 | + //Fade confirmation field and validation option in or out | |
| 2438 | + function addConf() { | |
| 2439 | + /*jshint validthis:true */ | |
| 2440 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 2441 | + var val = jQuery( this ).val(); | |
| 2442 | + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ); | |
| 2443 | + | |
| 2444 | + toggleValidationBox( val !== '', '.frm_conf_details' + fieldId ); | |
| 2445 | + | |
| 2446 | + if ( val !== '' ) { | |
| 2447 | + //Add default validation message if empty | |
| 2448 | + var valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' ); | |
| 2449 | + if ( valMsg.val() === '' ) { | |
| 2450 | + valMsg.val( frm_admin_js.default_conf ); | |
| 2451 | + } | |
| 2452 | + | |
| 2453 | + setConfirmationFieldDescriptions( fieldId ); | |
| 2454 | + | |
| 2455 | + //Add or remove class for confirmation field styling | |
| 2456 | + if ( val === 'inline' ) { | |
| 2457 | + $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' ); | |
| 2458 | + } else if ( val === 'below' ) { | |
| 2459 | + $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' ); | |
| 2460 | + } | |
| 2461 | + jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' ); | |
| 2462 | + } else { | |
| 2463 | + jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' ); | |
| 2464 | + setTimeout( function() { | |
| 2465 | + $thisField.removeClass( 'frm_conf_inline frm_conf_below' ); | |
| 2466 | + }, 200 ); | |
| 2467 | + } | |
| 2468 | + } | |
| 2469 | + | |
| 2470 | + function setConfirmationFieldDescriptions( fieldId ) { | |
| 2471 | + var fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value; | |
| 2472 | + | |
| 2473 | + var fieldDescription = document.getElementById( 'field_description_' + fieldId ); | |
| 2474 | + var hiddenDescName = 'field_options[description_' + fieldId + ']'; | |
| 2475 | + var newValue = frm_admin_js['enter_' + fieldType]; | |
| 2476 | + maybeSetNewDescription( fieldDescription, hiddenDescName, newValue ); | |
| 2477 | + | |
| 2478 | + var confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId ); | |
| 2479 | + var hiddenConfName = 'field_options[conf_desc_' + fieldId + ']'; | |
| 2480 | + var newConfValue = frm_admin_js['confirm_' + fieldType]; | |
| 2481 | + maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue ); | |
| 2482 | + } | |
| 2483 | + | |
| 2484 | + function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) { | |
| 2485 | + if ( descriptionDiv.innerHTML === frm_admin_js.desc ) { | |
| 2486 | + | |
| 2487 | + // Set the visible description value and the hidden description value | |
| 2488 | + descriptionDiv.innerHTML = newValue; | |
| 2489 | + document.getElementsByName( hiddenName )[0].value = newValue; | |
| 2490 | + } | |
| 2491 | + } | |
| 2492 | + | |
| 2493 | + function initBulkOptionsOverlay() { | |
| 2494 | + /*jshint validthis:true */ | |
| 2495 | + var $info = initModal( '#frm-bulk-modal', '700px' ); | |
| 2496 | + if ( $info === false ) { | |
| 2497 | + return; | |
| 2498 | + } | |
| 2499 | + | |
| 2500 | + jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset ); | |
| 2501 | + | |
| 2502 | + jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) { | |
| 2503 | + event.preventDefault(); | |
| 2504 | + var i, key, label, | |
| 2505 | + content = '', | |
| 2506 | + fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ), | |
| 2507 | + separate = usingSeparateValues( fieldId ), | |
| 2508 | + optList = document.getElementById( 'frm_field_' + fieldId + '_opts' ), | |
| 2509 | + opts = optList.getElementsByTagName( 'li' ), | |
| 2510 | + product = isProductField( fieldId ); | |
| 2511 | + | |
| 2512 | + document.getElementById( 'bulk-field-id' ).value = fieldId; | |
| 2513 | + | |
| 2514 | + for ( i = 0; i < opts.length; i++ ) { | |
| 2515 | + key = opts[i].getAttribute( 'data-optkey' ); | |
| 2516 | + if ( key !== '000' ) { | |
| 2517 | + label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0]; | |
| 2518 | + if ( typeof label !== 'undefined' ) { | |
| 2519 | + content += label.value; | |
| 2520 | + if ( separate ) { | |
| 2521 | + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value; | |
| 2522 | + } | |
| 2523 | + if ( product ) { | |
| 2524 | + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value; | |
| 2525 | + } | |
| 2526 | + content += '\r\n'; | |
| 2527 | + } | |
| 2528 | + } | |
| 2529 | + | |
| 2530 | + if ( i >= opts.length - 1 ) { | |
| 2531 | + document.getElementById( 'frm_bulk_options' ).value = content; | |
| 2532 | + } | |
| 2533 | + } | |
| 2534 | + | |
| 2535 | + $info.dialog( 'open' ); | |
| 2536 | + | |
| 2537 | + return false; | |
| 2538 | + }); | |
| 2539 | + | |
| 2540 | + jQuery( '#frm-update-bulk-opts' ).on( 'click', function() { | |
| 2541 | + var fieldId = document.getElementById( 'bulk-field-id' ).value; | |
| 2542 | + this.classList.add( 'frm_loading_button' ); | |
| 2543 | + frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info ); | |
| 2544 | + }); | |
| 2545 | + } | |
| 2546 | + | |
| 2547 | + function insertBulkPreset( event ) { | |
| 2548 | + /*jshint validthis:true */ | |
| 2549 | + var opts = JSON.parse( this.getAttribute( 'data-opts' ) ); | |
| 2550 | + event.preventDefault(); | |
| 2551 | + document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' ); | |
| 2552 | + return false; | |
| 2553 | + } | |
| 2554 | + | |
| 2555 | + //Add new option or "Other" option to radio/checkbox/dropdown | |
| 2556 | + function addFieldOption() { | |
| 2557 | + /*jshint validthis:true */ | |
| 2558 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 2559 | + newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ), | |
| 2560 | + optType = jQuery( this ).data( 'opttype' ), | |
| 2561 | + optKey = 0, | |
| 2562 | + oldKey = '000', | |
| 2563 | + lastKey = getHighestOptKey( fieldId ); | |
| 2564 | + | |
| 2565 | + if ( lastKey !== oldKey ) { | |
| 2566 | + optKey = lastKey + 1; | |
| 2567 | + } | |
| 2568 | + | |
| 2569 | + //Update hidden field | |
| 2570 | + if ( optType === 'other' ) { | |
| 2571 | + document.getElementById( 'other_input_' + fieldId ).value = 1; | |
| 2572 | + | |
| 2573 | + //Hide "Add Other" option now if this is radio field | |
| 2574 | + var ftype = jQuery( this ).data( 'ftype' ); | |
| 2575 | + if ( ftype === 'radio' || ftype === 'select' ) { | |
| 2576 | + jQuery( this ).fadeOut( 'slow' ); | |
| 2577 | + } | |
| 2578 | + | |
| 2579 | + var data = { | |
| 2580 | + action: 'frm_add_field_option', | |
| 2581 | + field_id: fieldId, | |
| 2582 | + opt_key: optKey, | |
| 2583 | + opt_type: optType, | |
| 2584 | + nonce: frmGlobal.nonce | |
| 2585 | + }; | |
| 2586 | + jQuery.post( ajaxurl, data, function( msg ) { | |
| 2587 | + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg ); | |
| 2588 | + resetDisplayedOpts( fieldId ); | |
| 2589 | + }); | |
| 2590 | + } else { | |
| 2591 | + newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' ); | |
| 2592 | + newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' ); | |
| 2593 | + newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' ); | |
| 2594 | + newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' ); | |
| 2595 | + newOption = newOption.replace( 'frm_hidden frm_option_template', '' ); | |
| 2596 | + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption ); | |
| 2597 | + resetDisplayedOpts( fieldId ); | |
| 2598 | + } | |
| 2599 | + } | |
| 2600 | + | |
| 2601 | + function getHighestOptKey( fieldId ) { | |
| 2602 | + var i = 0, | |
| 2603 | + optKey = 0, | |
| 2604 | + opts = jQuery( '#frm_field_' + fieldId + '_opts li' ), | |
| 2605 | + lastKey = 0; | |
| 2606 | + | |
| 2607 | + for ( i; i < opts.length; i++ ) { | |
| 2608 | + optKey = opts[i].getAttribute( 'data-optkey' ); | |
| 2609 | + if ( opts.length === 1 ) { | |
| 2610 | + return optKey; | |
| 2611 | + } | |
| 2612 | + if ( optKey !== '000' ) { | |
| 2613 | + optKey = optKey.replace( 'other_', '' ); | |
| 2614 | + optKey = parseInt( optKey, 10 ); | |
| 2615 | + } | |
| 2616 | + | |
| 2617 | + if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) { | |
| 2618 | + lastKey = optKey; | |
| 2619 | + } | |
| 2620 | + } | |
| 2621 | + | |
| 2622 | + return lastKey; | |
| 2623 | + } | |
| 2624 | + | |
| 2625 | + function toggleMultSel() { | |
| 2626 | + /*jshint validthis:true */ | |
| 2627 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 2628 | + toggleMultiSelect( fieldId, this.value ); | |
| 2629 | + } | |
| 2630 | + | |
| 2631 | + function toggleMultiSelect( fieldId, value ) { | |
| 2632 | + var setting = jQuery( '.frm_multiple_cont_' + fieldId ); | |
| 2633 | + if ( value === 'select' ) { | |
| 2634 | + setting.fadeIn( 'fast' ); | |
| 2635 | + } else { | |
| 2636 | + setting.fadeOut( 'fast' ); | |
| 2637 | + } | |
| 2638 | + } | |
| 2639 | + | |
| 2640 | + function toggleSepValues() { | |
| 2641 | + /*jshint validthis:true */ | |
| 2642 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 2643 | + toggle( jQuery( '.field_' + fieldId + '_option_key' ) ); | |
| 2644 | + jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' ); | |
| 2645 | + } | |
| 2646 | + | |
| 2647 | + function toggleImageOptions() { | |
| 2648 | + /*jshint validthis:true */ | |
| 2649 | + var hasImageOptions, imageSize, | |
| 2650 | + $field = jQuery( this ).closest( '.frm-single-settings' ), | |
| 2651 | + fieldId = $field.data( 'fid' ), | |
| 2652 | + displayField = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 2653 | + | |
| 2654 | + refreshOptionDisplayNow( jQuery( this ) ); | |
| 2655 | + | |
| 2656 | + toggle( jQuery( '.field_' + fieldId + '_image_id' ) ); | |
| 2657 | + toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) ); | |
| 2658 | + toggle( jQuery( '.frm_image_size_' + fieldId ) ); | |
| 2659 | + toggle( jQuery( '.frm_alignment_' + fieldId ) ); | |
| 2660 | + toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) ); | |
| 2661 | + | |
| 2662 | + hasImageOptions = imagesAsOptions( fieldId ); | |
| 2663 | + | |
| 2664 | + if ( hasImageOptions ) { | |
| 2665 | + setAlignment( fieldId, 'inline' ); | |
| 2666 | + removeImageSizeClasses( displayField ); | |
| 2667 | + imageSize = getImageOptionSize( fieldId ); | |
| 2668 | + displayField.classList.add( 'frm_image_options' ); | |
| 2669 | + displayField.classList.add( 'frm_image_size_' + imageSize ); | |
| 2670 | + $field.find( '.frm-bulk-edit-link' ).hide(); | |
| 2671 | + } else { | |
| 2672 | + displayField.classList.remove( 'frm_image_options' ); | |
| 2673 | + removeImageSizeClasses( displayField ); | |
| 2674 | + setAlignment( fieldId, 'block' ); | |
| 2675 | + $field.find( '.frm-bulk-edit-link' ).show(); | |
| 2676 | + } | |
| 2677 | + } | |
| 2678 | + | |
| 2679 | + function removeImageSizeClasses( field ) { | |
| 2680 | + field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' ); | |
| 2681 | + } | |
| 2682 | + | |
| 2683 | + function setAlignment( fieldId, alignment ) { | |
| 2684 | + jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' ); | |
| 2685 | + } | |
| 2686 | + | |
| 2687 | + function setImageSize() { | |
| 2688 | + var $field = jQuery( this ).closest( '.frm-single-settings' ), | |
| 2689 | + fieldId = $field.data( 'fid' ), | |
| 2690 | + displayField = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 2691 | + | |
| 2692 | + refreshOptionDisplay(); | |
| 2693 | + | |
| 2694 | + if ( imagesAsOptions( fieldId ) ) { | |
| 2695 | + removeImageSizeClasses( displayField ); | |
| 2696 | + displayField.classList.add( 'frm_image_options' ); | |
| 2697 | + displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) ); | |
| 2698 | + } | |
| 2699 | + } | |
| 2700 | + | |
| 2701 | + function refreshOptionDisplayNow( object ) { | |
| 2702 | + var $field = object.closest( '.frm-single-settings' ), | |
| 2703 | + fieldID = $field.data( 'fid' ); | |
| 2704 | + jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' ); | |
| 2705 | + } | |
| 2706 | + | |
| 2707 | + function refreshOptionDisplay() { | |
| 2708 | + /*jshint validthis:true */ | |
| 2709 | + refreshOptionDisplayNow( jQuery( this ) ); | |
| 2710 | + } | |
| 2711 | + | |
| 2712 | + function addImageToOption( event ) { | |
| 2713 | + var fileFrame, | |
| 2714 | + $this = jQuery( this ), | |
| 2715 | + $field = $this.closest( '.frm-single-settings' ), | |
| 2716 | + $imagePreview = $this.closest( '.frm_image_preview_wrapper' ), | |
| 2717 | + fieldId = $field.data( 'fid' ), | |
| 2718 | + postID = 0; | |
| 2719 | + | |
| 2720 | + event.preventDefault(); | |
| 2721 | + | |
| 2722 | + wp.media.model.settings.post.id = postID; | |
| 2723 | + | |
| 2724 | + fileFrame = wp.media.frames.file_frame = wp.media({ | |
| 2725 | + multiple: false, | |
| 2726 | + library: { | |
| 2727 | + type: [ 'image' ] | |
| 2728 | + } | |
| 2729 | + }); | |
| 2730 | + | |
| 2731 | + fileFrame.on( 'select', function() { | |
| 2732 | + const attachment = fileFrame.state().get( 'selection' ).first().toJSON(); | |
| 2733 | + $imagePreview.find( 'img' ).attr( 'src', attachment.url ); | |
| 2734 | + $imagePreview.find( '.frm_image_preview_frame' ).show(); | |
| 2735 | + $imagePreview.find( '.frm_image_preview_title' ).text( attachment.filename ); | |
| 2736 | + $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url ); | |
| 2737 | + $imagePreview.find( '.frm_choose_image_box' ).hide(); | |
| 2738 | + $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' ); | |
| 2739 | + wp.media.model.settings.post.id = postID; | |
| 2740 | + }); | |
| 2741 | + | |
| 2742 | + fileFrame.open(); | |
| 2743 | + } | |
| 2744 | + | |
| 2745 | + function removeImageFromOption( event ) { | |
| 2746 | + var $this = jQuery( this ), | |
| 2747 | + $field = $this.closest( '.frm-single-settings' ), | |
| 2748 | + fieldId = $field.data( 'fid' ), | |
| 2749 | + previewWrapper = $this.closest( '.frm_image_preview_wrapper' ); | |
| 2750 | + | |
| 2751 | + event.preventDefault(); | |
| 2752 | + event.stopPropagation(); | |
| 2753 | + | |
| 2754 | + previewWrapper.find( 'img' ).attr( 'src', '' ); | |
| 2755 | + previewWrapper.find( '.frm_image_preview_frame' ).hide(); | |
| 2756 | + previewWrapper.find( '.frm_choose_image_box' ).show(); | |
| 2757 | + previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' ); | |
| 2758 | + } | |
| 2759 | + | |
| 2760 | + function toggleMultiselect() { | |
| 2761 | + /*jshint validthis:true */ | |
| 2762 | + var dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' ); | |
| 2763 | + if ( this.checked ) { | |
| 2764 | + dropdown.attr( 'multiple', 'multiple' ); | |
| 2765 | + } else { | |
| 2766 | + dropdown.removeAttr( 'multiple' ); | |
| 2767 | + } | |
| 2768 | + } | |
| 2769 | + | |
| 2770 | + /** | |
| 2771 | + * Allow typing on form switcher click without an extra click to search. | |
| 2772 | + */ | |
| 2773 | + function focusSearchBox() { | |
| 2774 | + var searchBox = document.getElementById( 'dropform-search-input' ); | |
| 2775 | + if ( searchBox !== null ) { | |
| 2776 | + setTimeout( function() { | |
| 2777 | + searchBox.focus(); | |
| 2778 | + }, 100 ); | |
| 2779 | + } | |
| 2780 | + } | |
| 2781 | + | |
| 2782 | + /** | |
| 2783 | + * If a field is clicked in the builder, prevent inputs from changing. | |
| 2784 | + */ | |
| 2785 | + function stopFieldFocus( e ) { | |
| 2786 | + e.preventDefault(); | |
| 2787 | + } | |
| 2788 | + | |
| 2789 | + function deleteFieldOption() { | |
| 2790 | + /*jshint validthis:true */ | |
| 2791 | + var otherInput, | |
| 2792 | + parentLi = this.parentNode, | |
| 2793 | + parentUl = parentLi.parentNode, | |
| 2794 | + fieldId = this.getAttribute( 'data-fid' ); | |
| 2795 | + | |
| 2796 | + jQuery( parentLi ).fadeOut( 'slow', function() { | |
| 2797 | + jQuery( parentLi ).remove(); | |
| 2798 | + | |
| 2799 | + var hasOther = jQuery( parentUl ).find( '.frm_other_option' ); | |
| 2800 | + if ( hasOther.length < 1 ) { | |
| 2801 | + otherInput = document.getElementById( 'other_input_' + fieldId ); | |
| 2802 | + if ( otherInput !== null ) { | |
| 2803 | + otherInput.value = 0; | |
| 2804 | + } | |
| 2805 | + jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' ); | |
| 2806 | + } | |
| 2807 | + }); | |
| 2808 | + } | |
| 2809 | + | |
| 2810 | + /** | |
| 2811 | + * If a radio button is set as default, allow a click to | |
| 2812 | + * deselect it. | |
| 2813 | + */ | |
| 2814 | + function maybeUncheckRadio() { | |
| 2815 | + var $self, uncheck, unbind, up; | |
| 2816 | + | |
| 2817 | + /*jshint validthis:true */ | |
| 2818 | + $self = jQuery( this ); | |
| 2819 | + if ( $self.is( ':checked' ) ) { | |
| 2820 | + uncheck = function() { | |
| 2821 | + setTimeout( function() { | |
| 2822 | + $self.prop( 'checked', false ); | |
| 2823 | + }, 0 ); | |
| 2824 | + }; | |
| 2825 | + unbind = function() { | |
| 2826 | + $self.off( 'mouseup', up ); | |
| 2827 | + }; | |
| 2828 | + up = function() { | |
| 2829 | + uncheck(); | |
| 2830 | + unbind(); | |
| 2831 | + }; | |
| 2832 | + $self.on( 'mouseup', up ); | |
| 2833 | + $self.one( 'mouseout', unbind ); | |
| 2834 | + } | |
| 2835 | + } | |
| 2836 | + | |
| 2837 | + /** | |
| 2838 | + * If the field option has the default text, clear it out on click. | |
| 2839 | + */ | |
| 2840 | + function maybeClearOptText() { | |
| 2841 | + /*jshint validthis:true */ | |
| 2842 | + if ( this.value === frm_admin_js.new_option ) { | |
| 2843 | + this.setAttribute( 'data-value-on-focus', this.value ); | |
| 2844 | + this.value = ''; | |
| 2845 | + } | |
| 2846 | + } | |
| 2847 | + | |
| 2848 | + function clickDeleteField() { | |
| 2849 | + /*jshint validthis:true */ | |
| 2850 | + var confirmMsg = frm_admin_js.conf_delete, | |
| 2851 | + maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode, | |
| 2852 | + li = maybeDivider.parentNode, | |
| 2853 | + field = jQuery( this ).closest( 'li.form-field' ), | |
| 2854 | + fieldId = field.data( 'fid' ); | |
| 2855 | + | |
| 2856 | + if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) { | |
| 2857 | + return false; | |
| 2858 | + } | |
| 2859 | + | |
| 2860 | + // If deleting a section, use a special message. | |
| 2861 | + if ( maybeDivider.className === 'divider_section_only' ) { | |
| 2862 | + confirmMsg = frm_admin_js.conf_delete_sec; | |
| 2863 | + this.setAttribute( 'data-frmcaution', frm_admin_js.caution ); | |
| 2864 | + } | |
| 2865 | + | |
| 2866 | + this.setAttribute( 'data-frmverify', confirmMsg ); | |
| 2867 | + this.setAttribute( 'data-deletefield', fieldId ); | |
| 2868 | + | |
| 2869 | + closeOpenFieldDropdowns(); | |
| 2870 | + | |
| 2871 | + confirmLinkClick( this ); | |
| 2872 | + return false; | |
| 2873 | + } | |
| 2874 | + | |
| 2875 | + function clickSelectField() { | |
| 2876 | + this.closest( 'li.form-field' ).click(); | |
| 2877 | + } | |
| 2878 | + | |
| 2879 | + function clickFieldGroupLayout() { | |
| 2880 | + var hoverTarget, sizeOfFieldGroup, popupWrapper; | |
| 2881 | + | |
| 2882 | + hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 2883 | + | |
| 2884 | + if ( null === hoverTarget ) { | |
| 2885 | + return; | |
| 2886 | + } | |
| 2887 | + | |
| 2888 | + deselectFields(); | |
| 2889 | + | |
| 2890 | + sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) ); | |
| 2891 | + | |
| 2892 | + hoverTarget.classList.add( 'frm-has-open-field-group-popup' ); | |
| 2893 | + jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick ); | |
| 2894 | + | |
| 2895 | + popupWrapper = div(); | |
| 2896 | + popupWrapper.style.position = 'relative'; | |
| 2897 | + popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) ); | |
| 2898 | + this.parentNode.appendChild( popupWrapper ); | |
| 2899 | + } | |
| 2900 | + | |
| 2901 | + function destroyFieldGroupPopupOnOutsideClick( event ) { | |
| 2902 | + if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) { | |
| 2903 | + return; | |
| 2904 | + } | |
| 2905 | + if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) { | |
| 2906 | + destroyFieldGroupPopup(); | |
| 2907 | + } | |
| 2908 | + } | |
| 2909 | + | |
| 2910 | + function getSizeOfFieldGroupFromChildElement( element ) { | |
| 2911 | + var $ul = jQuery( element ).closest( 'ul' ); | |
| 2912 | + if ( $ul.length ) { | |
| 2913 | + return getFieldsInRow( $ul ).length; | |
| 2914 | + } | |
| 2915 | + return getSelectedFieldCount(); | |
| 2916 | + } | |
| 2917 | + | |
| 2918 | + function getFieldGroupPopup( sizeOfFieldGroup, childElement ) { | |
| 2919 | + var popup, wrapper, rowLayoutOptions, ul; | |
| 2920 | + | |
| 2921 | + popup = document.getElementById( 'frm_field_group_popup' ); | |
| 2922 | + if ( null === popup ) { | |
| 2923 | + popup = div(); | |
| 2924 | + } else { | |
| 2925 | + popup.innerHTML = ''; | |
| 2926 | + } | |
| 2927 | + | |
| 2928 | + popup.id = 'frm_field_group_popup'; | |
| 2929 | + | |
| 2930 | + wrapper = div(); | |
| 2931 | + wrapper.style.padding = '0 24px 12px'; | |
| 2932 | + wrapper.appendChild( getRowLayoutTitle() ); | |
| 2933 | + | |
| 2934 | + rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup ); | |
| 2935 | + | |
| 2936 | + ul = childElement.closest( 'ul.frm_sorting' ); | |
| 2937 | + if ( null !== ul ) { | |
| 2938 | + maybeMarkRowLayoutAsActive( ul, rowLayoutOptions ); | |
| 2939 | + } | |
| 2940 | + | |
| 2941 | + wrapper.appendChild( rowLayoutOptions ); | |
| 2942 | + | |
| 2943 | + popup.appendChild( wrapper ); | |
| 2944 | + popup.appendChild( separator() ); | |
| 2945 | + | |
| 2946 | + popup.appendChild( getCustomLayoutOption() ); | |
| 2947 | + popup.appendChild( getBreakIntoDifferentRowsOption() ); | |
| 2948 | + | |
| 2949 | + return popup; | |
| 2950 | + } | |
| 2951 | + | |
| 2952 | + function maybeMarkRowLayoutAsActive( activeRow, options ) { | |
| 2953 | + var length, index, currentRow; | |
| 2954 | + | |
| 2955 | + length = options.children.length; | |
| 2956 | + for ( index = 0; index < length; ++index ) { | |
| 2957 | + currentRow = options.children[ index ]; | |
| 2958 | + if ( rowLayoutsMatch( currentRow, activeRow ) ) { | |
| 2959 | + currentRow.classList.add( 'frm-active-row-layout' ); | |
| 2960 | + return; | |
| 2961 | + } | |
| 2962 | + } | |
| 2963 | + } | |
| 2964 | + | |
| 2965 | + function separator() { | |
| 2966 | + var hr = document.createElement( 'hr' ); | |
| 2967 | + return hr; | |
| 2968 | + } | |
| 2969 | + | |
| 2970 | + function getCustomLayoutOption() { | |
| 2971 | + var option = div(); | |
| 2972 | + option.textContent = __( 'Custom layout', 'formidable' ); | |
| 2973 | + jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) ); | |
| 2974 | + option.classList.add( 'frm-custom-field-group-layout' ); | |
| 2975 | + return option; | |
| 2976 | + } | |
| 2977 | + | |
| 2978 | + function getIconClone( iconId ) { | |
| 2979 | + var clone = document.getElementById( iconId ).cloneNode( true ); | |
| 2980 | + clone.id = ''; | |
| 2981 | + return clone; | |
| 2982 | + } | |
| 2983 | + | |
| 2984 | + function getBreakIntoDifferentRowsOption() { | |
| 2985 | + var option = div(); | |
| 2986 | + option.textContent = __( 'Break into rows', 'formidable' ); | |
| 2987 | + jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) ); | |
| 2988 | + option.classList.add( 'frm-break-field-group' ); | |
| 2989 | + return option; | |
| 2990 | + } | |
| 2991 | + | |
| 2992 | + function getRowLayoutTitle() { | |
| 2993 | + var rowLayoutTitle = div(); | |
| 2994 | + rowLayoutTitle.classList.add( 'frm-row-layout-title' ); | |
| 2995 | + rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' ); | |
| 2996 | + return rowLayoutTitle; | |
| 2997 | + } | |
| 2998 | + | |
| 2999 | + function getRowLayoutOptions( size ) { | |
| 3000 | + var wrapper, padding; | |
| 3001 | + | |
| 3002 | + wrapper = getEmptyGridContainer(); | |
| 3003 | + if ( 5 !== size ) { | |
| 3004 | + wrapper.appendChild( getRowLayoutOption( size, 'even' ) ); | |
| 3005 | + } | |
| 3006 | + if ( size % 2 === 1 ) { | |
| 3007 | + // only include the middle option for odd numbers because even doesn't make a lot of sense. | |
| 3008 | + wrapper.appendChild( getRowLayoutOption( size, 'middle' ) ); | |
| 3009 | + } | |
| 3010 | + if ( size < 6 ) { | |
| 3011 | + wrapper.appendChild( getRowLayoutOption( size, 'left' ) ); | |
| 3012 | + wrapper.appendChild( getRowLayoutOption( size, 'right' ) ); | |
| 3013 | + } else { | |
| 3014 | + padding = div(); | |
| 3015 | + padding.classList.add( 'frm_fourth' ); | |
| 3016 | + wrapper.prepend( padding ); | |
| 3017 | + } | |
| 3018 | + | |
| 3019 | + return wrapper; | |
| 3020 | + } | |
| 3021 | + | |
| 3022 | + function getRowLayoutOption( size, type ) { | |
| 3023 | + var option, useClass; | |
| 3024 | + | |
| 3025 | + option = div(); | |
| 3026 | + option.classList.add( 'frm-row-layout-option' ); | |
| 3027 | + | |
| 3028 | + switch ( size ) { | |
| 3029 | + case 6: | |
| 3030 | + useClass = 'frm_half'; | |
| 3031 | + break; | |
| 3032 | + case 5: | |
| 3033 | + useClass = 'frm_third'; | |
| 3034 | + break; | |
| 3035 | + default: | |
| 3036 | + useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third'; | |
| 3037 | + break; | |
| 3038 | + } | |
| 3039 | + | |
| 3040 | + option.classList.add( useClass ); | |
| 3041 | + option.setAttribute( 'layout-type', type ); | |
| 3042 | + | |
| 3043 | + option.appendChild( getRowForSizeAndType( size, type ) ); | |
| 3044 | + return option; | |
| 3045 | + } | |
| 3046 | + | |
| 3047 | + function rowLayoutsMatch( row1, row2 ) { | |
| 3048 | + return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 ); | |
| 3049 | + } | |
| 3050 | + | |
| 3051 | + function getRowLayoutAsKey( row ) { | |
| 3052 | + var $fields, sizes; | |
| 3053 | + if ( row.classList.contains( 'frm-row-layout-option' ) ) { | |
| 3054 | + $fields = jQuery( row ).find( '.frm_grid_container' ).children(); | |
| 3055 | + } else { | |
| 3056 | + $fields = getFieldsInRow( jQuery( row ) ); | |
| 3057 | + } | |
| 3058 | + sizes = []; | |
| 3059 | + $fields.each( | |
| 3060 | + function() { | |
| 3061 | + sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) ); | |
| 3062 | + } | |
| 3063 | + ); | |
| 3064 | + return sizes.join( '-' ); | |
| 3065 | + } | |
| 3066 | + | |
| 3067 | + function getRowForSizeAndType( size, type ) { | |
| 3068 | + var row, index, block; | |
| 3069 | + | |
| 3070 | + row = getEmptyGridContainer(); | |
| 3071 | + for ( index = 0; index < size; ++index ) { | |
| 3072 | + block = div(); | |
| 3073 | + block.classList.add( getClassForBlock( size, type, index ) ); | |
| 3074 | + block.style.height = '16px'; | |
| 3075 | + block.style.background = '#9EA9B8'; | |
| 3076 | + block.style.borderRadius = '1px'; | |
| 3077 | + row.appendChild( block ); | |
| 3078 | + } | |
| 3079 | + | |
| 3080 | + return row; | |
| 3081 | + } | |
| 3082 | + | |
| 3083 | + /** | |
| 3084 | + * @param {int} size 2-6. | |
| 3085 | + * @param {string} type even, middle, left, or right. | |
| 3086 | + * @param {int} index 0-5. | |
| 3087 | + * @returns string | |
| 3088 | + */ | |
| 3089 | + function getClassForBlock( size, type, index ) { | |
| 3090 | + if ( 'even' === type ) { | |
| 3091 | + return getEvenClassForSize( size, index ); | |
| 3092 | + } else if ( 'middle' === type ) { | |
| 3093 | + if ( 3 === size ) { | |
| 3094 | + return 1 === index ? 'frm6' : 'frm3'; | |
| 3095 | + } | |
| 3096 | + if ( 5 === size ) { | |
| 3097 | + return 2 === index ? 'frm4' : 'frm2'; | |
| 3098 | + } | |
| 3099 | + } else if ( 'left' === type ) { | |
| 3100 | + return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size ); | |
| 3101 | + } else if ( 'right' === type ) { | |
| 3102 | + return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size ); | |
| 3103 | + } | |
| 3104 | + return 'frm12'; | |
| 3105 | + } | |
| 3106 | + | |
| 3107 | + function getEvenClassForSize( size, index ) { | |
| 3108 | + if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) { | |
| 3109 | + return getLayoutClassForSize( 12 / size ); | |
| 3110 | + } | |
| 3111 | + if ( 5 === size && 'undefined' !== typeof index ) { | |
| 3112 | + return 0 === index ? 'frm4' : 'frm2'; | |
| 3113 | + } | |
| 3114 | + return 'frm12'; | |
| 3115 | + } | |
| 3116 | + | |
| 3117 | + function getSmallClassForSize( size ) { | |
| 3118 | + switch ( size ) { | |
| 3119 | + case 2: case 3: | |
| 3120 | + return 'frm3'; | |
| 3121 | + case 4: | |
| 3122 | + return 'frm2'; | |
| 3123 | + case 5: | |
| 3124 | + return 'frm2'; | |
| 3125 | + case 6: | |
| 3126 | + return 'frm1'; | |
| 3127 | + } | |
| 3128 | + return 'frm12'; | |
| 3129 | + } | |
| 3130 | + | |
| 3131 | + function getLargeClassForSize( size ) { | |
| 3132 | + switch ( size ) { | |
| 3133 | + case 2: | |
| 3134 | + return 'frm9'; | |
| 3135 | + case 3: case 4: | |
| 3136 | + return 'frm6'; | |
| 3137 | + case 5: | |
| 3138 | + return 'frm4'; | |
| 3139 | + case 6: | |
| 3140 | + return 'frm7'; | |
| 3141 | + } | |
| 3142 | + return 'frm12'; | |
| 3143 | + } | |
| 3144 | + | |
| 3145 | + function getEmptyGridContainer() { | |
| 3146 | + var wrapper = div(); | |
| 3147 | + wrapper.classList.add( 'frm_grid_container' ); | |
| 3148 | + return wrapper; | |
| 3149 | + } | |
| 3150 | + | |
| 3151 | + function div() { | |
| 3152 | + var element = document.createElement( 'div' ); | |
| 3153 | + return element; | |
| 3154 | + } | |
| 3155 | + | |
| 3156 | + function handleFieldGroupLayoutOptionClick() { | |
| 3157 | + var type, row; | |
| 3158 | + type = this.getAttribute( 'layout-type' ); | |
| 3159 | + row = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3160 | + size = getFieldsInRow( jQuery( row ) ).length; | |
| 3161 | + syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type ); | |
| 3162 | + destroyFieldGroupPopup(); | |
| 3163 | + } | |
| 3164 | + | |
| 3165 | + function handleFieldGroupLayoutOptionInsideMergeClick() { | |
| 3166 | + var $ul, type; | |
| 3167 | + $ul = mergeSelectedFieldGroups(); | |
| 3168 | + type = this.getAttribute( 'layout-type' ); | |
| 3169 | + syncLayoutClasses( getFieldsInRow( $ul ).first(), type ); | |
| 3170 | + unselectFieldGroups(); | |
| 3171 | + } | |
| 3172 | + | |
| 3173 | + function mergeSelectedFieldGroups() { | |
| 3174 | + var $selectedFieldGroups = jQuery( '.frm-selected-field-group' ), | |
| 3175 | + $firstGroupUl = $selectedFieldGroups.first(); | |
| 3176 | + $selectedFieldGroups.not( $firstGroupUl ).each( | |
| 3177 | + function() { | |
| 3178 | + getFieldsInRow( jQuery( this ) ).each( | |
| 3179 | + function() { | |
| 3180 | + var previousParent = this.parentNode; | |
| 3181 | + getFieldsInRow( $firstGroupUl ).last().after( this ); | |
| 3182 | + if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) { | |
| 3183 | + // clean up the previous field group if we've removed all of its fields. | |
| 3184 | + previousParent.closest( 'li.frm_field_box' ).remove(); | |
| 3185 | + } | |
| 3186 | + } | |
| 3187 | + ); | |
| 3188 | + } | |
| 3189 | + ); | |
| 3190 | + updateFieldOrder(); | |
| 3191 | + syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() ); | |
| 3192 | + return $firstGroupUl; | |
| 3193 | + } | |
| 3194 | + | |
| 3195 | + function customFieldGroupLayoutClick() { | |
| 3196 | + var $fields; | |
| 3197 | + if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) { | |
| 3198 | + return; | |
| 3199 | + } | |
| 3200 | + $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) ); | |
| 3201 | + setupCustomLayoutOptions( $fields ); | |
| 3202 | + } | |
| 3203 | + | |
| 3204 | + function setupCustomLayoutOptions( $fields ) { | |
| 3205 | + var size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton; | |
| 3206 | + | |
| 3207 | + size = $fields.length; | |
| 3208 | + | |
| 3209 | + popup = document.getElementById( 'frm_field_group_popup' ); | |
| 3210 | + popup.innerHTML = ''; | |
| 3211 | + | |
| 3212 | + wrapper = div(); | |
| 3213 | + wrapper.style.padding = '24px'; | |
| 3214 | + | |
| 3215 | + layoutClass = getEvenClassForSize( 5 === size ? 6 : size ); | |
| 3216 | + | |
| 3217 | + inputRow = div(); | |
| 3218 | + inputRow.style.padding = '20px 0'; | |
| 3219 | + inputRow.classList.add( 'frm_grid_container' ); | |
| 3220 | + | |
| 3221 | + if ( 5 === size ) { | |
| 3222 | + // add a span to pad the inputs by 1 column, to account for the missing 2 columns. | |
| 3223 | + paddingElement = document.createElement( 'span' ); | |
| 3224 | + paddingElement.classList.add( 'frm1' ); | |
| 3225 | + inputRow.appendChild( paddingElement ); | |
| 3226 | + } | |
| 3227 | + | |
| 3228 | + inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false; | |
| 3229 | + if ( false !== inputValueOverride && inputValueOverride >= 12 ) { | |
| 3230 | + inputValueOverride = Math.floor( 12 / size ); | |
| 3231 | + } | |
| 3232 | + | |
| 3233 | + for ( index = 0; index < size; ++index ) { | |
| 3234 | + inputField = document.createElement( 'input' ); | |
| 3235 | + inputField.type = 'text'; | |
| 3236 | + inputField.classList.add( layoutClass ); | |
| 3237 | + inputField.classList.add( 'frm-custom-grid-size-input' ); | |
| 3238 | + inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) ); | |
| 3239 | + inputRow.appendChild( inputField ); | |
| 3240 | + } | |
| 3241 | + | |
| 3242 | + heading = div(); | |
| 3243 | + heading.classList.add( 'frm-builder-popup-heading' ); | |
| 3244 | + heading.textContent = __( 'Enter number of columns for each field', 'formidable' ); | |
| 3245 | + | |
| 3246 | + label = div(); | |
| 3247 | + label.classList.add( 'frm-builder-popup-subheading' ); | |
| 3248 | + label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' ); | |
| 3249 | + | |
| 3250 | + wrapper.appendChild( heading ); | |
| 3251 | + wrapper.appendChild( label ); | |
| 3252 | + | |
| 3253 | + wrapper.appendChild( inputRow ); | |
| 3254 | + | |
| 3255 | + buttonsWrapper = div(); | |
| 3256 | + buttonsWrapper.style.textAlign = 'right'; | |
| 3257 | + | |
| 3258 | + cancelButton = getSecondaryButton(); | |
| 3259 | + cancelButton.textContent = __( 'Cancel', 'formidable' ); | |
| 3260 | + cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' ); | |
| 3261 | + cancelButton.style.marginRight = '10px'; | |
| 3262 | + | |
| 3263 | + saveButton = getPrimaryButton(); | |
| 3264 | + saveButton.textContent = __( 'Save', 'formidable' ); | |
| 3265 | + saveButton.classList.add( 'frm-save-custom-field-group-layout' ); | |
| 3266 | + | |
| 3267 | + buttonsWrapper.appendChild( cancelButton ); | |
| 3268 | + buttonsWrapper.appendChild( saveButton ); | |
| 3269 | + | |
| 3270 | + wrapper.appendChild( buttonsWrapper ); | |
| 3271 | + | |
| 3272 | + popup.appendChild( wrapper ); | |
| 3273 | + } | |
| 3274 | + | |
| 3275 | + function customFieldGroupLayoutInsideMergeClick() { | |
| 3276 | + $fields = jQuery( '.frm-selected-field-group li.form-field' ); | |
| 3277 | + setupCustomLayoutOptions( $fields ); | |
| 3278 | + } | |
| 3279 | + | |
| 3280 | + function getPrimaryButton() { | |
| 3281 | + var button = getButton(); | |
| 3282 | + button.classList.add( 'button-primary', 'frm-button-primary' ); | |
| 3283 | + return button; | |
| 3284 | + } | |
| 3285 | + | |
| 3286 | + function getSecondaryButton() { | |
| 3287 | + var button = getButton(); | |
| 3288 | + button.classList.add( 'button-secondary', 'frm-button-secondary' ); | |
| 3289 | + return button; | |
| 3290 | + } | |
| 3291 | + | |
| 3292 | + function getButton() { | |
| 3293 | + var button = document.createElement( 'a' ); | |
| 3294 | + button.setAttribute( 'href', '#' ); | |
| 3295 | + button.classList.add( 'button' ); | |
| 3296 | + button.style.textDecoration = 'none'; | |
| 3297 | + return button; | |
| 3298 | + } | |
| 3299 | + | |
| 3300 | + function getSizeOfLayoutClass( className ) { | |
| 3301 | + switch ( className ) { | |
| 3302 | + case 'frm_half': | |
| 3303 | + return 6; | |
| 3304 | + case 'frm_third': | |
| 3305 | + return 4; | |
| 3306 | + case 'frm_two_thirds': | |
| 3307 | + return 8; | |
| 3308 | + case 'frm_fourth': | |
| 3309 | + return 3; | |
| 3310 | + case 'frm_three_fourths': | |
| 3311 | + return 9; | |
| 3312 | + case 'frm_sixth': | |
| 3313 | + return 2; | |
| 3314 | + } | |
| 3315 | + | |
| 3316 | + if ( 0 === className.indexOf( 'frm' ) ) { | |
| 3317 | + return parseInt( className.substr( 3 ) ); | |
| 3318 | + } | |
| 3319 | + | |
| 3320 | + // Anything missing a layout class should be a full width row. | |
| 3321 | + return 12; | |
| 3322 | + } | |
| 3323 | + | |
| 3324 | + function getLayoutClassName( classList ) { | |
| 3325 | + var classes, index, currentClass; | |
| 3326 | + classes = getLayoutClasses(); | |
| 3327 | + for ( index = 0; index < classes.length; ++index ) { | |
| 3328 | + currentClass = classes[ index ]; | |
| 3329 | + if ( classList.contains( currentClass ) ) { | |
| 3330 | + return currentClass; | |
| 3331 | + } | |
| 3332 | + } | |
| 3333 | + return ''; | |
| 3334 | + } | |
| 3335 | + | |
| 3336 | + function getLayoutClassForSize( size ) { | |
| 3337 | + return 'frm' + size; | |
| 3338 | + } | |
| 3339 | + | |
| 3340 | + function breakFieldGroupClick() { | |
| 3341 | + var row = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3342 | + breakRow( row ); | |
| 3343 | + destroyFieldGroupPopup(); | |
| 3344 | + } | |
| 3345 | + | |
| 3346 | + function breakRow( row ) { | |
| 3347 | + getFieldsInRow( jQuery( row ) ).each( | |
| 3348 | + function( index ) { | |
| 3349 | + if ( 0 !== index ) { | |
| 3350 | + jQuery( row ).closest( 'li' ).after( wrapFieldLi( this ) ); | |
| 3351 | + } | |
| 3352 | + stripLayoutFromFields( jQuery( this ) ); | |
| 3353 | + } | |
| 3354 | + ); | |
| 3355 | + } | |
| 3356 | + | |
| 3357 | + function stripLayoutFromFields( field ) { | |
| 3358 | + syncLayoutClasses( field, 'clear' ); | |
| 3359 | + } | |
| 3360 | + | |
| 3361 | + function focusFieldGroupInputOnClick() { | |
| 3362 | + this.select(); | |
| 3363 | + } | |
| 3364 | + | |
| 3365 | + function cancelCustomFieldGroupClick() { | |
| 3366 | + revertToFieldGroupPopupFirstPage( this ); | |
| 3367 | + } | |
| 3368 | + | |
| 3369 | + function revertToFieldGroupPopupFirstPage( triggerElement ) { | |
| 3370 | + jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith( | |
| 3371 | + getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement ) | |
| 3372 | + ); | |
| 3373 | + } | |
| 3374 | + | |
| 3375 | + function destroyFieldGroupPopup() { | |
| 3376 | + var popup, wrapper; | |
| 3377 | + popup = document.getElementById( 'frm_field_group_popup' ); | |
| 3378 | + if ( popup === null ) { | |
| 3379 | + return; | |
| 3380 | + } | |
| 3381 | + wrapper = document.querySelector( '.frm-has-open-field-group-popup' ); | |
| 3382 | + if ( null !== wrapper ) { | |
| 3383 | + wrapper.classList.remove( 'frm-has-open-field-group-popup' ); | |
| 3384 | + popup.parentNode.remove(); | |
| 3385 | + } | |
| 3386 | + jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick ); | |
| 3387 | + } | |
| 3388 | + | |
| 3389 | + function saveCustomFieldGroupClick() { | |
| 3390 | + var syncDetails, $controls, $ul; | |
| 3391 | + | |
| 3392 | + syncDetails = []; | |
| 3393 | + | |
| 3394 | + jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) ) | |
| 3395 | + .each( | |
| 3396 | + function() { | |
| 3397 | + syncDetails.push( parseInt( this.value ) ); | |
| 3398 | + } | |
| 3399 | + ); | |
| 3400 | + | |
| 3401 | + $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) ); | |
| 3402 | + | |
| 3403 | + if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) { | |
| 3404 | + syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails ); | |
| 3405 | + } else { | |
| 3406 | + $ul = mergeSelectedFieldGroups(); | |
| 3407 | + syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails ); | |
| 3408 | + unselectFieldGroups(); | |
| 3409 | + } | |
| 3410 | + | |
| 3411 | + destroyFieldGroupPopup(); | |
| 3412 | + } | |
| 3413 | + | |
| 3414 | + function fieldGroupClick( e ) { | |
| 3415 | + var hoverTarget, ctrlOrCmdKeyIsDown, shiftKeyIsDown, groupIsActive, $selectedFieldGroups, numberOfSelectedGroups, selectedField, $firstGroup, $range; | |
| 3416 | + | |
| 3417 | + if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) { | |
| 3418 | + // only continue if the group itself was clicked / ignore when a field is clicked. | |
| 3419 | + return; | |
| 3420 | + } | |
| 3421 | + | |
| 3422 | + hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3423 | + if ( hoverTarget === null ) { | |
| 3424 | + return; | |
| 3425 | + } | |
| 3426 | + | |
| 3427 | + ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey; | |
| 3428 | + shiftKeyIsDown = e.shiftKey; | |
| 3429 | + groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' ); | |
| 3430 | + $selectedFieldGroups = jQuery( '.frm-selected-field-group' ); | |
| 3431 | + numberOfSelectedGroups = $selectedFieldGroups.length; | |
| 3432 | + | |
| 3433 | + if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) { | |
| 3434 | + // multi-selecting | |
| 3435 | + | |
| 3436 | + selectedField = document.querySelector( 'li.form-field.selected' ); | |
| 3437 | + if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) { | |
| 3438 | + // count a selected field on its own as a selected field group when multiselecting. | |
| 3439 | + selectedField.parentNode.classList.add( 'frm-selected-field-group' ); | |
| 3440 | + ++numberOfSelectedGroups; | |
| 3441 | + } | |
| 3442 | + | |
| 3443 | + if ( ctrlOrCmdKeyIsDown ) { | |
| 3444 | + if ( groupIsActive ) { | |
| 3445 | + // unselect if holding ctrl or cmd and the group was already active. | |
| 3446 | + --numberOfSelectedGroups; | |
| 3447 | + hoverTarget.classList.remove( 'frm-selected-field-group' ); | |
| 3448 | + syncAfterMultiSelect( numberOfSelectedGroups ); | |
| 3449 | + return; // exit early to avoid adding back frm-selected-field-group | |
| 3450 | + } else { | |
| 3451 | + ++numberOfSelectedGroups; | |
| 3452 | + } | |
| 3453 | + } else if ( shiftKeyIsDown && ! groupIsActive ) { | |
| 3454 | + ++numberOfSelectedGroups; // include the one we're selecting right now. | |
| 3455 | + $firstGroup = $selectedFieldGroups.first(); | |
| 3456 | + | |
| 3457 | + if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) { | |
| 3458 | + $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode ); | |
| 3459 | + } else { | |
| 3460 | + $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode ); | |
| 3461 | + } | |
| 3462 | + | |
| 3463 | + $range.each( | |
| 3464 | + function() { | |
| 3465 | + var $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' ); | |
| 3466 | + if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) { | |
| 3467 | + ++numberOfSelectedGroups; | |
| 3468 | + $fieldGroup.addClass( 'frm-selected-field-group' ); | |
| 3469 | + } | |
| 3470 | + } | |
| 3471 | + ); | |
| 3472 | + | |
| 3473 | + // when holding shift and clicking, text gets selected. unselect it. | |
| 3474 | + document.getSelection().removeAllRanges(); | |
| 3475 | + } | |
| 3476 | + } else { | |
| 3477 | + // not multi-selecting | |
| 3478 | + unselectFieldGroups(); | |
| 3479 | + } | |
| 3480 | + | |
| 3481 | + hoverTarget.classList.add( 'frm-selected-field-group' ); | |
| 3482 | + syncAfterMultiSelect( numberOfSelectedGroups ); | |
| 3483 | + | |
| 3484 | + jQuery( document ).off( 'click', unselectFieldGroups ); | |
| 3485 | + jQuery( document ).on( 'click', unselectFieldGroups ); | |
| 3486 | + } | |
| 3487 | + | |
| 3488 | + function syncAfterMultiSelect( numberOfSelectedGroups ) { | |
| 3489 | + clearSettingsBox( true ); // unselect any fields if one is selected. | |
| 3490 | + if ( numberOfSelectedGroups >= 2 ) { | |
| 3491 | + addFieldMultiselectPopup(); | |
| 3492 | + } else { | |
| 3493 | + maybeRemoveMultiselectPopup(); | |
| 3494 | + } | |
| 3495 | + maybeRemoveGroupHoverTarget(); | |
| 3496 | + } | |
| 3497 | + | |
| 3498 | + function unselectFieldGroups( event ) { | |
| 3499 | + if ( 'undefined' !== typeof event ) { | |
| 3500 | + if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) { | |
| 3501 | + return; | |
| 3502 | + } | |
| 3503 | + if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) { | |
| 3504 | + return; | |
| 3505 | + } | |
| 3506 | + if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) { | |
| 3507 | + return; | |
| 3508 | + } | |
| 3509 | + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) { | |
| 3510 | + return; | |
| 3511 | + } | |
| 3512 | + if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) { | |
| 3513 | + return; | |
| 3514 | + } | |
| 3515 | + } | |
| 3516 | + jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' ); | |
| 3517 | + jQuery( document ).off( 'click', unselectFieldGroups ); | |
| 3518 | + maybeRemoveMultiselectPopup(); | |
| 3519 | + } | |
| 3520 | + | |
| 3521 | + function maybeRemoveMultiselectPopup() { | |
| 3522 | + var popup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 3523 | + if ( null !== popup ) { | |
| 3524 | + popup.remove(); | |
| 3525 | + } | |
| 3526 | + } | |
| 3527 | + | |
| 3528 | + function addFieldMultiselectPopup() { | |
| 3529 | + getFieldMultiselectPopup(); | |
| 3530 | + } | |
| 3531 | + | |
| 3532 | + function getFieldMultiselectPopup() { | |
| 3533 | + var popup, mergeOption, caret, verticalSeparator, deleteOption; | |
| 3534 | + | |
| 3535 | + popup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 3536 | + | |
| 3537 | + if ( null !== popup ) { | |
| 3538 | + popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergable() ); | |
| 3539 | + return popup; | |
| 3540 | + } | |
| 3541 | + | |
| 3542 | + popup = div(); | |
| 3543 | + popup.id = 'frm_field_multiselect_popup'; | |
| 3544 | + if ( ! selectedFieldsAreMergable() ) { | |
| 3545 | + popup.classList.add( 'frm-unmergable' ); | |
| 3546 | + } | |
| 3547 | + | |
| 3548 | + mergeOption = div(); | |
| 3549 | + mergeOption.classList.add( 'frm-merge-fields-into-row' ); | |
| 3550 | + mergeOption.textContent = __( 'Merge into row', 'formidable' ); | |
| 3551 | + | |
| 3552 | + caret = document.createElement( 'a' ); | |
| 3553 | + caret.style.marginLeft = '5px'; | |
| 3554 | + caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' ); | |
| 3555 | + caret.setAttribute( 'href', '#' ); | |
| 3556 | + mergeOption.appendChild( caret ); | |
| 3557 | + | |
| 3558 | + popup.appendChild( mergeOption ); | |
| 3559 | + | |
| 3560 | + verticalSeparator = div(); | |
| 3561 | + verticalSeparator.classList.add( 'frm-multiselect-popup-separator' ); | |
| 3562 | + popup.appendChild( verticalSeparator ); | |
| 3563 | + | |
| 3564 | + deleteOption = div(); | |
| 3565 | + deleteOption.classList.add( 'frm-delete-field-groups' ); | |
| 3566 | + deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) ); | |
| 3567 | + popup.appendChild( deleteOption ); | |
| 3568 | + | |
| 3569 | + document.getElementById( 'post-body-content' ).appendChild( popup ); | |
| 3570 | + | |
| 3571 | + jQuery( popup ).hide().fadeIn(); | |
| 3572 | + | |
| 3573 | + return popup; | |
| 3574 | + } | |
| 3575 | + | |
| 3576 | + function selectedFieldsAreMergable() { | |
| 3577 | + var selectedFieldGroups, totalFieldCount, length, index, fieldGroup; | |
| 3578 | + selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' ); | |
| 3579 | + length = selectedFieldGroups.length; | |
| 3580 | + totalFieldCount = 0; | |
| 3581 | + for ( index = 0; index < length; ++index ) { | |
| 3582 | + fieldGroup = selectedFieldGroups[ index ]; | |
| 3583 | + if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) { | |
| 3584 | + return false; | |
| 3585 | + } | |
| 3586 | + totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length; | |
| 3587 | + if ( totalFieldCount > 6 ) { | |
| 3588 | + return false; | |
| 3589 | + } | |
| 3590 | + } | |
| 3591 | + return true; | |
| 3592 | + } | |
| 3593 | + | |
| 3594 | + function mergeFieldsIntoRowClick( event ) { | |
| 3595 | + var size, popup; | |
| 3596 | + | |
| 3597 | + if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) { | |
| 3598 | + // prevent clicks within the popup from triggering the button again. | |
| 3599 | + return; | |
| 3600 | + } | |
| 3601 | + | |
| 3602 | + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) { | |
| 3603 | + // avoid switching back to the first page when clicking the custom option nested inside of the merge option. | |
| 3604 | + return; | |
| 3605 | + } | |
| 3606 | + | |
| 3607 | + size = getSelectedFieldCount(); | |
| 3608 | + popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild ); | |
| 3609 | + this.appendChild( popup ); | |
| 3610 | + } | |
| 3611 | + | |
| 3612 | + function getSelectedFieldCount() { | |
| 3613 | + var count = 0; | |
| 3614 | + jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each( | |
| 3615 | + function() { | |
| 3616 | + count += getFieldsInRow( jQuery( this ) ).length; | |
| 3617 | + } | |
| 3618 | + ); | |
| 3619 | + return count; | |
| 3620 | + } | |
| 3621 | + | |
| 3622 | + function deleteFieldGroupsClick() { | |
| 3623 | + var fieldIdsToDelete, deleteOnConfirm; | |
| 3624 | + | |
| 3625 | + fieldIdsToDelete = getSelectedFieldIds(); | |
| 3626 | + deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete ); | |
| 3627 | + document.getElementById( 'frm_field_multiselect_popup' ).remove(); | |
| 3628 | + | |
| 3629 | + this.setAttribute( 'data-frmcaution', __( 'Heads up', 'formidable' ) ); | |
| 3630 | + /* translators: %1$s: Number of fields that are selected to be deleted. */ | |
| 3631 | + this.setAttribute( 'data-frmverify', __( 'Are you sure you want to delete these %1$s selected fields?', 'formidable' ).replace( '%1$s', fieldIdsToDelete.length ) ); | |
| 3632 | + confirmLinkClick( this ); | |
| 3633 | + | |
| 3634 | + jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm ); | |
| 3635 | + jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() { | |
| 3636 | + jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm ); | |
| 3637 | + }); | |
| 3638 | + } | |
| 3639 | + | |
| 3640 | + function getSelectedFieldIds() { | |
| 3641 | + var deleteFieldIds = []; | |
| 3642 | + jQuery( '.frm-selected-field-group > li.form-field' ) | |
| 3643 | + .not( '.ui-sortable-helper' ) | |
| 3644 | + .each( | |
| 3645 | + function() { | |
| 3646 | + deleteFieldIds.push( this.dataset.fid ); | |
| 3647 | + } | |
| 3648 | + ); | |
| 3649 | + return deleteFieldIds; | |
| 3650 | + } | |
| 3651 | + | |
| 3652 | + function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) { | |
| 3653 | + return function( event ) { | |
| 3654 | + event.preventDefault(); | |
| 3655 | + deleteAllSelectedFieldGroups( deleteFieldIds ); | |
| 3656 | + }; | |
| 3657 | + } | |
| 3658 | + | |
| 3659 | + function deleteAllSelectedFieldGroups( deleteFieldIds ) { | |
| 3660 | + deleteFieldIds.forEach( | |
| 3661 | + function( fieldId ) { | |
| 3662 | + deleteField( fieldId ); | |
| 3663 | + } | |
| 3664 | + ); | |
| 3665 | + } | |
| 3666 | + | |
| 3667 | + function deleteFieldConfirmed() { | |
| 3668 | + /*jshint validthis:true */ | |
| 3669 | + deleteFields( this.getAttribute( 'data-deletefield' ) ); | |
| 3670 | + } | |
| 3671 | + | |
| 3672 | + function deleteFields( fieldId ) { | |
| 3673 | + var field = jQuery( '#frm_field_id_' + fieldId ); | |
| 3674 | + | |
| 3675 | + deleteField( fieldId ); | |
| 3676 | + | |
| 3677 | + if ( field.hasClass( 'edit_field_type_divider' ) ) { | |
| 3678 | + field.find( 'li.frm_field_box' ).each( function() { | |
| 3679 | + //TODO: maybe delete only end section | |
| 3680 | + //if(n.hasClass('edit_field_type_end_divider')){ | |
| 3681 | + deleteField( this.getAttribute( 'data-fid' ) ); | |
| 3682 | + //} | |
| 3683 | + }); | |
| 3684 | + } | |
| 3685 | + toggleSectionHolder(); | |
| 3686 | + } | |
| 3687 | + | |
| 3688 | + function deleteField( fieldId ) { | |
| 3689 | + jQuery.ajax({ | |
| 3690 | + type: 'POST', | |
| 3691 | + url: ajaxurl, | |
| 3692 | + data: { | |
| 3693 | + action: 'frm_delete_field', | |
| 3694 | + field_id: fieldId, | |
| 3695 | + nonce: frmGlobal.nonce | |
| 3696 | + }, | |
| 3697 | + success: function() { | |
| 3698 | + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ), | |
| 3699 | + settings = jQuery( '#frm-single-settings-' + fieldId ); | |
| 3700 | + | |
| 3701 | + // Remove settings from sidebar. | |
| 3702 | + if ( settings.is( ':visible' ) ) { | |
| 3703 | + document.getElementById( 'frm_insert_fields_tab' ).click(); | |
| 3704 | + } | |
| 3705 | + settings.remove(); | |
| 3706 | + | |
| 3707 | + $thisField.fadeOut( 'slow', function() { | |
| 3708 | + var $section = $thisField.closest( '.start_divider' ), | |
| 3709 | + type = $thisField.data( 'type' ), | |
| 3710 | + $adjacentFields = $thisField.siblings( 'li.form-field' ), | |
| 3711 | + $liWrapper; | |
| 3712 | + | |
| 3713 | + if ( ! $adjacentFields.length ) { | |
| 3714 | + if ( $thisField.is( '.edit_field_type_end_divider' ) ) { | |
| 3715 | + $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings(); | |
| 3716 | + } else { | |
| 3717 | + $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent(); | |
| 3718 | + } | |
| 3719 | + } | |
| 3720 | + | |
| 3721 | + $thisField.remove(); | |
| 3722 | + if ( type === 'break' ) { | |
| 3723 | + renumberPageBreaks(); | |
| 3724 | + } | |
| 3725 | + if ( type === 'summary' ) { | |
| 3726 | + reenableAddSummaryBtn(); | |
| 3727 | + } | |
| 3728 | + if ( type === 'product' ) { | |
| 3729 | + maybeHideQuantityProductFieldOption(); | |
| 3730 | + // a product field attached to a quantity field earlier might be the one deleted, so re-populate | |
| 3731 | + popAllProductFields(); | |
| 3732 | + } | |
| 3733 | + if ( jQuery( '#frm-show-fields li' ).length === 0 ) { | |
| 3734 | + document.getElementById( 'frm_form_editor_container' ).classList.remove( 'frm-has-fields' ); | |
| 3735 | + } else if ( $section.length ) { | |
| 3736 | + toggleOneSectionHolder( $section ); | |
| 3737 | + } | |
| 3738 | + if ( $adjacentFields.length ) { | |
| 3739 | + syncLayoutClasses( $adjacentFields.first() ); | |
| 3740 | + } else { | |
| 3741 | + $liWrapper.remove(); | |
| 3742 | + } | |
| 3743 | + }); | |
| 3744 | + } | |
| 3745 | + }); | |
| 3746 | + } | |
| 3747 | + | |
| 3748 | + function addFieldLogicRow() { | |
| 3749 | + /*jshint validthis:true */ | |
| 3750 | + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 3751 | + formId = thisFormId, | |
| 3752 | + logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' ); | |
| 3753 | + jQuery.ajax({ | |
| 3754 | + type: 'POST', | |
| 3755 | + url: ajaxurl, | |
| 3756 | + data: { | |
| 3757 | + action: 'frm_add_logic_row', | |
| 3758 | + form_id: formId, | |
| 3759 | + field_id: id, | |
| 3760 | + nonce: frmGlobal.nonce, | |
| 3761 | + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ), | |
| 3762 | + fields: getFieldList() | |
| 3763 | + }, | |
| 3764 | + success: function( html ) { | |
| 3765 | + jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() { | |
| 3766 | + var logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) ); | |
| 3767 | + logicRow.append( html ); | |
| 3768 | + logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' ); | |
| 3769 | + }); | |
| 3770 | + } | |
| 3771 | + }); | |
| 3772 | + return false; | |
| 3773 | + } | |
| 3774 | + | |
| 3775 | + function getNewRowId( rows, replace, defaultValue ) { | |
| 3776 | + if ( ! rows.length ) { | |
| 3777 | + return 'undefined' !== typeof defaultValue ? defaultValue : 0; | |
| 3778 | + } | |
| 3779 | + return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1; | |
| 3780 | + } | |
| 3781 | + | |
| 3782 | + function addWatchLookupRow() { | |
| 3783 | + /*jshint validthis:true */ | |
| 3784 | + var lastRowId, | |
| 3785 | + id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 3786 | + formId = thisFormId, | |
| 3787 | + lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children; | |
| 3788 | + jQuery.ajax({ | |
| 3789 | + type: 'POST', | |
| 3790 | + url: ajaxurl, | |
| 3791 | + data: { | |
| 3792 | + action: 'frm_add_watch_lookup_row', | |
| 3793 | + form_id: formId, | |
| 3794 | + field_id: id, | |
| 3795 | + row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ), | |
| 3796 | + nonce: frmGlobal.nonce | |
| 3797 | + }, | |
| 3798 | + success: function( newRow ) { | |
| 3799 | + var watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) ); | |
| 3800 | + watchRowBlock.append( newRow ); | |
| 3801 | + watchRowBlock.fadeIn( 'slow' ); | |
| 3802 | + } | |
| 3803 | + }); | |
| 3804 | + return false; | |
| 3805 | + } | |
| 3806 | + | |
| 3807 | + function resetOptionTextDetails() { | |
| 3808 | + jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' ); | |
| 3809 | + jQuery( 'input[type="hidden"][name^=optionmap]' ).remove(); | |
| 3810 | + } | |
| 3811 | + | |
| 3812 | + function optionTextAlreadyExists( input ) { | |
| 3813 | + var fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ), | |
| 3814 | + optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ), | |
| 3815 | + index, | |
| 3816 | + optionInput; | |
| 3817 | + | |
| 3818 | + for ( index in optionInputs ) { | |
| 3819 | + optionInput = optionInputs[ index ]; | |
| 3820 | + if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) { | |
| 3821 | + return true; | |
| 3822 | + } | |
| 3823 | + } | |
| 3824 | + | |
| 3825 | + return false; | |
| 3826 | + } | |
| 3827 | + | |
| 3828 | + function onOptionTextFocus() { | |
| 3829 | + var input, | |
| 3830 | + fieldId; | |
| 3831 | + | |
| 3832 | + if ( this.getAttribute( 'data-value-on-load' ) === null ) { | |
| 3833 | + this.setAttribute( 'data-value-on-load', this.value ); | |
| 3834 | + | |
| 3835 | + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' ); | |
| 3836 | + input = document.createElement( 'input' ); | |
| 3837 | + input.value = this.value; | |
| 3838 | + input.setAttribute( 'type', 'hidden' ); | |
| 3839 | + input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' ); | |
| 3840 | + this.parentNode.appendChild( input ); | |
| 3841 | + | |
| 3842 | + if ( typeof optionMap[ fieldId ] === 'undefined' ) { | |
| 3843 | + optionMap[ fieldId ] = {}; | |
| 3844 | + } | |
| 3845 | + | |
| 3846 | + optionMap[ fieldId ][ this.value ] = input; | |
| 3847 | + } | |
| 3848 | + | |
| 3849 | + if ( this.getAttribute( 'data-duplicate' ) === 'true' ) { | |
| 3850 | + this.removeAttribute( 'data-duplicate' ); | |
| 3851 | + | |
| 3852 | + // we want to use original value if actually still a duplicate | |
| 3853 | + if ( optionTextAlreadyExists( this ) ) { | |
| 3854 | + this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) ); | |
| 3855 | + return; | |
| 3856 | + } | |
| 3857 | + } | |
| 3858 | + | |
| 3859 | + if ( '' !== this.value || frm_admin_js.new_option !== this.getAttribute( 'data-value-on-focus' ) ) { | |
| 3860 | + this.setAttribute( 'data-value-on-focus', this.value ); | |
| 3861 | + } | |
| 3862 | + } | |
| 3863 | + | |
| 3864 | + function onOptionTextBlur() { | |
| 3865 | + var originalValue, | |
| 3866 | + oldValue = this.getAttribute( 'data-value-on-focus' ), | |
| 3867 | + newValue = this.value, | |
| 3868 | + fieldId, | |
| 3869 | + fieldIndex, | |
| 3870 | + logicId, | |
| 3871 | + row, | |
| 3872 | + rowLength, | |
| 3873 | + rowIndex, | |
| 3874 | + valueSelect, | |
| 3875 | + opts, | |
| 3876 | + fieldIds, | |
| 3877 | + settingId, | |
| 3878 | + setting, | |
| 3879 | + optionMatches, | |
| 3880 | + option; | |
| 3881 | + | |
| 3882 | + if ( oldValue === newValue ) { | |
| 3883 | + return; | |
| 3884 | + } | |
| 3885 | + | |
| 3886 | + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' ); | |
| 3887 | + originalValue = this.getAttribute( 'data-value-on-load' ); | |
| 3888 | + | |
| 3889 | + // check if the newValue is already mapped to another option | |
| 3890 | + // if it is, mark as duplicate and return | |
| 3891 | + if ( optionTextAlreadyExists( this ) ) { | |
| 3892 | + this.setAttribute( 'data-duplicate', 'true' ); | |
| 3893 | + | |
| 3894 | + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) { | |
| 3895 | + // unmap any other change that may have happened before instead of changing it to something unused | |
| 3896 | + optionMap[ fieldId ][ originalValue ].value = originalValue; | |
| 3897 | + } | |
| 3898 | + | |
| 3899 | + return; | |
| 3900 | + } | |
| 3901 | + | |
| 3902 | + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) { | |
| 3903 | + optionMap[ fieldId ][ originalValue ].value = newValue; | |
| 3904 | + } | |
| 3905 | + | |
| 3906 | + fieldIds = []; | |
| 3907 | + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ); | |
| 3908 | + rowLength = rows.length; | |
| 3909 | + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) { | |
| 3910 | + row = rows[ rowIndex ]; | |
| 3911 | + opts = row.querySelector( '.frm_logic_field_opts' ); | |
| 3912 | + | |
| 3913 | + if ( opts.value !== fieldId ) { | |
| 3914 | + continue; | |
| 3915 | + } | |
| 3916 | + | |
| 3917 | + logicId = row.id.split( '_' )[ 2 ]; | |
| 3918 | + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' ); | |
| 3919 | + | |
| 3920 | + if ( '' === oldValue ) { | |
| 3921 | + optionMatches = []; | |
| 3922 | + } else { | |
| 3923 | + optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' ); | |
| 3924 | + } | |
| 3925 | + | |
| 3926 | + if ( ! optionMatches.length ) { | |
| 3927 | + optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' ); | |
| 3928 | + | |
| 3929 | + if ( ! optionMatches.length ) { | |
| 3930 | + option = document.createElement( 'option' ); | |
| 3931 | + valueSelect.appendChild( option ); | |
| 3932 | + } | |
| 3933 | + } | |
| 3934 | + | |
| 3935 | + if ( optionMatches.length ) { | |
| 3936 | + option = optionMatches[ optionMatches.length - 1 ]; | |
| 3937 | + } | |
| 3938 | + | |
| 3939 | + option.setAttribute( 'value', newValue ); | |
| 3940 | + option.textContent = newValue; | |
| 3941 | + | |
| 3942 | + if ( fieldIds.indexOf( logicId ) === -1 ) { | |
| 3943 | + fieldIds.push( logicId ); | |
| 3944 | + } | |
| 3945 | + } | |
| 3946 | + | |
| 3947 | + for ( fieldIndex in fieldIds ) { | |
| 3948 | + settingId = fieldIds[ fieldIndex ]; | |
| 3949 | + setting = document.getElementById( 'frm-single-settings-' + settingId ); | |
| 3950 | + moveFieldSettings( setting ); | |
| 3951 | + } | |
| 3952 | + } | |
| 3953 | + | |
| 3954 | + function updateGetValueFieldSelection() { | |
| 3955 | + /*jshint validthis:true */ | |
| 3956 | + var fieldID = this.id.replace( 'get_values_form_', '' ); | |
| 3957 | + var fieldSelect = document.getElementById( 'get_values_field_' + fieldID ); | |
| 3958 | + var fieldType = this.getAttribute( 'data-fieldtype' ); | |
| 3959 | + | |
| 3960 | + if ( this.value === '' ) { | |
| 3961 | + fieldSelect.options.length = 1; | |
| 3962 | + } else { | |
| 3963 | + var formID = this.value; | |
| 3964 | + jQuery.ajax({ | |
| 3965 | + type: 'POST', url: ajaxurl, | |
| 3966 | + data: { | |
| 3967 | + action: 'frm_get_options_for_get_values_field', | |
| 3968 | + form_id: formID, | |
| 3969 | + field_type: fieldType, | |
| 3970 | + nonce: frmGlobal.nonce | |
| 3971 | + }, | |
| 3972 | + success: function( fields ) { | |
| 3973 | + fieldSelect.innerHTML = fields; | |
| 3974 | + } | |
| 3975 | + }); | |
| 3976 | + } | |
| 3977 | + } | |
| 3978 | + | |
| 3979 | + // Clear the Watch Fields option when Lookup field switches to "Text" option | |
| 3980 | + function maybeClearWatchFields() { | |
| 3981 | + /*jshint validthis:true */ | |
| 3982 | + var link, lookupBlock, | |
| 3983 | + fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' ); | |
| 3984 | + | |
| 3985 | + link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID ).parentNode; | |
| 3986 | + | |
| 3987 | + if ( this.value === 'text' ) { | |
| 3988 | + lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID ); | |
| 3989 | + if ( lookupBlock !== null ) { | |
| 3990 | + // Clear and hide the Watch Fields option | |
| 3991 | + lookupBlock.innerHTML = ''; | |
| 3992 | + link.classList.add( 'frm_hidden' ); | |
| 3993 | + | |
| 3994 | + // Hide the Watch Fields row | |
| 3995 | + link.previousElementSibling.style.display = 'none'; | |
| 3996 | + link.previousElementSibling.previousElementSibling.style.display = 'none'; | |
| 3997 | + link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none'; | |
| 3998 | + } | |
| 3999 | + } else { | |
| 4000 | + // Show the Watch Fields option | |
| 4001 | + link.classList.remove( 'frm_hidden' ); | |
| 4002 | + } | |
| 4003 | + | |
| 4004 | + toggleMultiSelect( fieldID, this.value ); | |
| 4005 | + } | |
| 4006 | + | |
| 4007 | + // Number the pages and hide/show the first page as needed. | |
| 4008 | + function renumberPageBreaks() { | |
| 4009 | + var i, containerClass, | |
| 4010 | + pages = document.getElementsByClassName( 'frm-page-num' ); | |
| 4011 | + | |
| 4012 | + if ( pages.length > 1 ) { | |
| 4013 | + document.getElementById( 'frm-fake-page' ).style.display = 'block'; | |
| 4014 | + for ( i = 0; i < pages.length; i++ ) { | |
| 4015 | + containerClass = pages[i].parentNode.parentNode.parentNode.classList; | |
| 4016 | + if ( i === 1 ) { | |
| 4017 | + // Hide previous button on page 1 | |
| 4018 | + containerClass.add( 'frm-first-page' ); | |
| 4019 | + } else { | |
| 4020 | + containerClass.remove( 'frm-first-page' ); | |
| 4021 | + } | |
| 4022 | + pages[i].innerHTML = ( i + 1 ); | |
| 4023 | + } | |
| 4024 | + } else { | |
| 4025 | + document.getElementById( 'frm-fake-page' ).style.display = 'none'; | |
| 4026 | + } | |
| 4027 | + } | |
| 4028 | + | |
| 4029 | + // The fake field works differently than real fields. | |
| 4030 | + function maybeCollapsePage() { | |
| 4031 | + /*jshint validthis:true */ | |
| 4032 | + var field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' ); | |
| 4033 | + if ( field.length ) { | |
| 4034 | + toggleCollapsePage( field ); | |
| 4035 | + } else { | |
| 4036 | + toggleCollapseFakePage(); | |
| 4037 | + } | |
| 4038 | + } | |
| 4039 | + | |
| 4040 | + // Find all fields in a page and hide/show them | |
| 4041 | + function toggleCollapsePage( field ) { | |
| 4042 | + var toCollapse = field.nextUntil( '.frm_field_box[data-ftype=break]' ); | |
| 4043 | + togglePage( field, toCollapse ); | |
| 4044 | + } | |
| 4045 | + | |
| 4046 | + function toggleCollapseFakePage() { | |
| 4047 | + var topLevel = document.getElementById( 'frm-fake-page' ), | |
| 4048 | + firstField = document.getElementById( 'frm-show-fields' ).firstElementChild, | |
| 4049 | + toCollapse = jQuery( firstField ).add( jQuery( firstField ).nextUntil( '.frm_field_box[data-ftype=break]' ) ); | |
| 4050 | + | |
| 4051 | + if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) { | |
| 4052 | + // Don't collapse if the first field is a page break. | |
| 4053 | + return; | |
| 4054 | + } | |
| 4055 | + | |
| 4056 | + togglePage( jQuery( topLevel ), toCollapse ); | |
| 4057 | + } | |
| 4058 | + | |
| 4059 | + function togglePage( field, toCollapse ) { | |
| 4060 | + var i, | |
| 4061 | + fieldCount = toCollapse.length, | |
| 4062 | + slide = Math.min( fieldCount, 3 ); | |
| 4063 | + | |
| 4064 | + if ( field.hasClass( 'frm-page-collapsed' ) ) { | |
| 4065 | + field.removeClass( 'frm-page-collapsed' ); | |
| 4066 | + toCollapse.removeClass( 'frm-is-collapsed' ); | |
| 4067 | + for ( i = 0; i < slide; i++ ) { | |
| 4068 | + if ( i === slide - 1 ) { | |
| 4069 | + jQuery( toCollapse[ i ]).slideDown( 150, function() { | |
| 4070 | + toCollapse.show(); | |
| 4071 | + }); | |
| 4072 | + } else { | |
| 4073 | + jQuery( toCollapse[ i ]).slideDown( 150 ); | |
| 4074 | + } | |
| 4075 | + } | |
| 4076 | + } else { | |
| 4077 | + field.addClass( 'frm-page-collapsed' ); | |
| 4078 | + toCollapse.addClass( 'frm-is-collapsed' ); | |
| 4079 | + for ( i = 0; i < slide; i++ ) { | |
| 4080 | + if ( i === slide - 1 ) { | |
| 4081 | + jQuery( toCollapse[ i ]).slideUp( 150, function() { | |
| 4082 | + toCollapse.css( 'cssText', 'display:none !important;' ); | |
| 4083 | + }); | |
| 4084 | + } else { | |
| 4085 | + jQuery( toCollapse[ i ]).slideUp( 150 ); | |
| 4086 | + } | |
| 4087 | + } | |
| 4088 | + } | |
| 4089 | + } | |
| 4090 | + | |
| 4091 | + function maybeCollapseSection() { | |
| 4092 | + /*jshint validthis:true */ | |
| 4093 | + var parentCont = this.parentNode.parentNode.parentNode.parentNode; | |
| 4094 | + | |
| 4095 | + parentCont.classList.toggle( 'frm-section-collapsed' ); | |
| 4096 | + } | |
| 4097 | + | |
| 4098 | + function maybeCollapseSettings() { | |
| 4099 | + /*jshint validthis:true */ | |
| 4100 | + this.classList.toggle( 'frm-collapsed' ); | |
| 4101 | + } | |
| 4102 | + | |
| 4103 | + function clickLabel() { | |
| 4104 | + if ( ! this.id ) { | |
| 4105 | + return; | |
| 4106 | + } | |
| 4107 | + | |
| 4108 | + /*jshint validthis:true */ | |
| 4109 | + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0], | |
| 4110 | + fieldId = this.id.replace( 'field_label_', '' ), | |
| 4111 | + fieldType = document.getElementById( 'field_options_type_' + fieldId ), | |
| 4112 | + fieldTypeName = fieldType.value; | |
| 4113 | + | |
| 4114 | + if ( typeof setting !== 'undefined' ) { | |
| 4115 | + if ( fieldType.tagName === 'SELECT' ) { | |
| 4116 | + fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase(); | |
| 4117 | + } else { | |
| 4118 | + fieldTypeName = fieldTypeName.replace( '_', ' ' ); | |
| 4119 | + } | |
| 4120 | + | |
| 4121 | + fieldTypeName = normalizeFieldName( fieldTypeName ); | |
| 4122 | + | |
| 4123 | + setTimeout( function() { | |
| 4124 | + if ( setting.value.toLowerCase() === fieldTypeName ) { | |
| 4125 | + setting.select(); | |
| 4126 | + } else { | |
| 4127 | + setting.focus(); | |
| 4128 | + } | |
| 4129 | + }, 50 ); | |
| 4130 | + } | |
| 4131 | + } | |
| 4132 | + | |
| 4133 | + function clickDescription() { | |
| 4134 | + /*jshint validthis:true */ | |
| 4135 | + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0]; | |
| 4136 | + if ( typeof setting !== 'undefined' ) { | |
| 4137 | + setTimeout( function() { | |
| 4138 | + setting.focus(); | |
| 4139 | + autoExpandSettings( setting ); | |
| 4140 | + }, 50 ); | |
| 4141 | + } | |
| 4142 | + } | |
| 4143 | + | |
| 4144 | + function autoExpandSettings( setting ) { | |
| 4145 | + var inSection = setting.closest( '.frm-collapse-me' ); | |
| 4146 | + if ( inSection !== null ) { | |
| 4147 | + inSection.previousElementSibling.classList.remove( 'frm-collapsed' ); | |
| 4148 | + } | |
| 4149 | + } | |
| 4150 | + | |
| 4151 | + function normalizeFieldName( fieldTypeName ) { | |
| 4152 | + if ( fieldTypeName === 'divider' ) { | |
| 4153 | + fieldTypeName = 'section'; | |
| 4154 | + } else if ( fieldTypeName === 'range' ) { | |
| 4155 | + fieldTypeName = 'slider'; | |
| 4156 | + } else if ( fieldTypeName === 'data' ) { | |
| 4157 | + fieldTypeName = 'dynamic'; | |
| 4158 | + } else if ( fieldTypeName === 'form' ) { | |
| 4159 | + fieldTypeName = 'embed form'; | |
| 4160 | + } | |
| 4161 | + return fieldTypeName; | |
| 4162 | + } | |
| 4163 | + | |
| 4164 | + function clickVis( e ) { | |
| 4165 | + /*jshint validthis:true */ | |
| 4166 | + var currentClass, originalList; | |
| 4167 | + | |
| 4168 | + currentClass = e.target.classList; | |
| 4169 | + | |
| 4170 | + if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) { | |
| 4171 | + return; | |
| 4172 | + } | |
| 4173 | + | |
| 4174 | + if ( this.closest( '.start_divider' ) !== null ) { | |
| 4175 | + e.stopPropagation(); | |
| 4176 | + } | |
| 4177 | + | |
| 4178 | + if ( this.classList.contains( 'edit_field_type_divider' ) ) { | |
| 4179 | + originalList = e.originalEvent.target.closest( 'ul.frm_sorting' ); | |
| 4180 | + if ( null !== originalList ) { | |
| 4181 | + // prevent section click if clicking a field group within a section. | |
| 4182 | + if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) { | |
| 4183 | + return; | |
| 4184 | + } | |
| 4185 | + } | |
| 4186 | + } | |
| 4187 | + | |
| 4188 | + clickAction( this ); | |
| 4189 | + } | |
| 4190 | + | |
| 4191 | + /** | |
| 4192 | + * Open Advanced settings on double click. | |
| 4193 | + */ | |
| 4194 | + function openAdvanced() { | |
| 4195 | + var fieldId = this.getAttribute( 'data-fid' ); | |
| 4196 | + autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) ); | |
| 4197 | + } | |
| 4198 | + | |
| 4199 | + function toggleRepeatButtons() { | |
| 4200 | + /*jshint validthis:true */ | |
| 4201 | + var $thisField = jQuery( this ).closest( '.frm_field_box' ); | |
| 4202 | + $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value ); | |
| 4203 | + if ( this.value === 'text' || this.value === 'both' ) { | |
| 4204 | + $thisField.find( '.frm_repeat_text' ).show(); | |
| 4205 | + $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' ); | |
| 4206 | + } else { | |
| 4207 | + $thisField.find( '.frm_repeat_text' ).hide(); | |
| 4208 | + $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' ); | |
| 4209 | + } | |
| 4210 | + } | |
| 4211 | + | |
| 4212 | + function checkRepeatLimit() { | |
| 4213 | + /*jshint validthis:true */ | |
| 4214 | + var val = this.value; | |
| 4215 | + if ( val !== '' && ( val < 2 || val > 200 ) ) { | |
| 4216 | + infoModal( frm_admin_js.repeat_limit_min ); | |
| 4217 | + this.value = ''; | |
| 4218 | + } | |
| 4219 | + } | |
| 4220 | + | |
| 4221 | + function checkCheckboxSelectionsLimit() { | |
| 4222 | + /*jshint validthis:true */ | |
| 4223 | + var val = this.value; | |
| 4224 | + if ( val !== '' && ( val < 1 || val > 200 ) ) { | |
| 4225 | + infoModal( frm_admin_js.checkbox_limit ); | |
| 4226 | + this.value = ''; | |
| 4227 | + } | |
| 4228 | + } | |
| 4229 | + | |
| 4230 | + function updateRepeatText( obj, addRemove ) { | |
| 4231 | + var $thisField = jQuery( obj ).closest( '.frm_field_box' ); | |
| 4232 | + $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value ); | |
| 4233 | + } | |
| 4234 | + | |
| 4235 | + function fieldsInSection( id ) { | |
| 4236 | + var children = []; | |
| 4237 | + jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() { | |
| 4238 | + children.push( jQuery( this ).data( 'fid' ) ); | |
| 4239 | + }); | |
| 4240 | + return children; | |
| 4241 | + } | |
| 4242 | + | |
| 4243 | + function toggleFormTax() { | |
| 4244 | + /*jshint validthis:true */ | |
| 4245 | + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 4246 | + var val = this.value; | |
| 4247 | + var $showFields = document.getElementById( 'frm_show_selected_fields_' + id ); | |
| 4248 | + var $showForms = document.getElementById( 'frm_show_selected_forms_' + id ); | |
| 4249 | + | |
| 4250 | + jQuery( $showForms ).find( 'select' ).val( '' ); | |
| 4251 | + if ( val === 'form' ) { | |
| 4252 | + $showForms.style.display = 'inline'; | |
| 4253 | + empty( $showFields ); | |
| 4254 | + } else { | |
| 4255 | + $showFields.style.display = 'none'; | |
| 4256 | + $showForms.style.display = 'none'; | |
| 4257 | + getTaxOrFieldSelection( val, id ); | |
| 4258 | + } | |
| 4259 | + | |
| 4260 | + } | |
| 4261 | + | |
| 4262 | + function resetOptOnChange() { | |
| 4263 | + /*jshint validthis:true */ | |
| 4264 | + var field = getFieldKeyFromOpt( this ), | |
| 4265 | + thisOpt = jQuery( this ).closest( '.frm_single_option' ); | |
| 4266 | + | |
| 4267 | + resetSingleOpt( field.fieldId, field.fieldKey, thisOpt ); | |
| 4268 | + } | |
| 4269 | + | |
| 4270 | + function getFieldKeyFromOpt( object ) { | |
| 4271 | + var allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' ), | |
| 4272 | + fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' ), | |
| 4273 | + fieldKey = allOpts.data( 'key' ); | |
| 4274 | + | |
| 4275 | + return { | |
| 4276 | + fieldId: fieldId, | |
| 4277 | + fieldKey: fieldKey | |
| 4278 | + }; | |
| 4279 | + } | |
| 4280 | + | |
| 4281 | + function resetSingleOpt( fieldId, fieldKey, thisOpt ) { | |
| 4282 | + var saved, text, defaultVal, previewInput, labelForDisplay, optContainer, | |
| 4283 | + optKey = thisOpt.data( 'optkey' ), | |
| 4284 | + separateValues = usingSeparateValues( fieldId ), | |
| 4285 | + single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ), | |
| 4286 | + baseName = 'field_options[options_' + fieldId + '][' + optKey + ']', | |
| 4287 | + label = jQuery( 'input[name="' + baseName + '[label]"]' ); | |
| 4288 | + | |
| 4289 | + if ( single.length < 1 ) { | |
| 4290 | + resetDisplayedOpts( fieldId ); | |
| 4291 | + | |
| 4292 | + // Set the default value. | |
| 4293 | + defaultVal = thisOpt.find( 'input[name^="default_value_"]' ); | |
| 4294 | + if ( defaultVal.is( ':checked' ) && label.length > 0 ) { | |
| 4295 | + jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() ); | |
| 4296 | + } | |
| 4297 | + return; | |
| 4298 | + } | |
| 4299 | + | |
| 4300 | + previewInput = single.children( 'input' ); | |
| 4301 | + | |
| 4302 | + if ( label.length < 1 ) { | |
| 4303 | + // Check for other label. | |
| 4304 | + label = jQuery( 'input[name="' + baseName + '"]' ); | |
| 4305 | + saved = label.val(); | |
| 4306 | + } else if ( separateValues ) { | |
| 4307 | + saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val(); | |
| 4308 | + } else { | |
| 4309 | + saved = label.val(); | |
| 4310 | + } | |
| 4311 | + | |
| 4312 | + if ( label.length < 1 ) { | |
| 4313 | + return; | |
| 4314 | + } | |
| 4315 | + | |
| 4316 | + // Set the displayed value. | |
| 4317 | + text = single[0].childNodes; | |
| 4318 | + | |
| 4319 | + if ( imagesAsOptions( fieldId ) ) { | |
| 4320 | + labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label ); | |
| 4321 | + optContainer = single.find( '.frm_image_option_container' ); | |
| 4322 | + | |
| 4323 | + if ( optContainer.length > 0 ) { | |
| 4324 | + optContainer.replaceWith( labelForDisplay ); | |
| 4325 | + } else { | |
| 4326 | + text[ text.length - 1 ].nodeValue = ''; | |
| 4327 | + single.append( labelForDisplay ); | |
| 4328 | + } | |
| 4329 | + } else { | |
| 4330 | + text[ text.length - 1 ].nodeValue = ' ' + label.val(); | |
| 4331 | + } | |
| 4332 | + | |
| 4333 | + // Set saved value. | |
| 4334 | + previewInput.val( saved ); | |
| 4335 | + | |
| 4336 | + // Set the default value. | |
| 4337 | + defaultVal = thisOpt.find( 'input[name^="default_value_"]' ); | |
| 4338 | + previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false ); | |
| 4339 | + } | |
| 4340 | + | |
| 4341 | + /** | |
| 4342 | + * Set the displayed value for an image option. | |
| 4343 | + */ | |
| 4344 | + function getImageDisplayValue( thisOpt, fieldId, label ) { | |
| 4345 | + var image, imageUrl, showLabelWithImage, fieldType; | |
| 4346 | + | |
| 4347 | + image = thisOpt.find( 'img' ); | |
| 4348 | + if ( image ) { | |
| 4349 | + imageUrl = image.attr( 'src' ); | |
| 4350 | + } | |
| 4351 | + | |
| 4352 | + showLabelWithImage = showingLabelWithImage( fieldId ); | |
| 4353 | + fieldType = radioOrCheckbox( fieldId ); | |
| 4354 | + return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType ); | |
| 4355 | + } | |
| 4356 | + | |
| 4357 | + function getImageOptionSize( fieldId ) { | |
| 4358 | + var val, | |
| 4359 | + field = document.getElementById( 'field_options_image_size_' + fieldId ), | |
| 4360 | + size = ''; | |
| 4361 | + | |
| 4362 | + if ( field !== null ) { | |
| 4363 | + val = field.value; | |
| 4364 | + if ( val !== '' ) { | |
| 4365 | + size = val; | |
| 4366 | + } | |
| 4367 | + } | |
| 4368 | + | |
| 4369 | + return size; | |
| 4370 | + } | |
| 4371 | + | |
| 4372 | + function resetDisplayedOpts( fieldId ) { | |
| 4373 | + var i, opts, type, placeholder, fieldInfo, | |
| 4374 | + input = jQuery( '[name^="item_meta[' + fieldId + ']"]' ); | |
| 4375 | + | |
| 4376 | + if ( input.length < 1 ) { | |
| 4377 | + return; | |
| 4378 | + } | |
| 4379 | + | |
| 4380 | + if ( input.is( 'select' ) ) { | |
| 4381 | + placeholder = document.getElementById( 'frm_placeholder_' + fieldId ); | |
| 4382 | + if ( placeholder !== null && placeholder.value === '' ) { | |
| 4383 | + fillDropdownOpts( input[0], { sourceID: fieldId }); | |
| 4384 | + } else { | |
| 4385 | + fillDropdownOpts( input[0], { | |
| 4386 | + sourceID: fieldId, | |
| 4387 | + placeholder: placeholder.value | |
| 4388 | + }); | |
| 4389 | + } | |
| 4390 | + } else { | |
| 4391 | + opts = getMultipleOpts( fieldId ); | |
| 4392 | + type = input.attr( 'type' ); | |
| 4393 | + jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' ); | |
| 4394 | + fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) ); | |
| 4395 | + | |
| 4396 | + var container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ), | |
| 4397 | + hasImageOptions = imagesAsOptions( fieldId ), | |
| 4398 | + imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '', | |
| 4399 | + imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '', | |
| 4400 | + isProduct = isProductField( fieldId ); | |
| 4401 | + | |
| 4402 | + for ( i = 0; i < opts.length; i++ ) { | |
| 4403 | + container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) ); | |
| 4404 | + } | |
| 4405 | + } | |
| 4406 | + | |
| 4407 | + adjustConditionalLogicOptionOrders( fieldId ); | |
| 4408 | + } | |
| 4409 | + | |
| 4410 | + function adjustConditionalLogicOptionOrders( fieldId ) { | |
| 4411 | + var row, opts, logicId, valueSelect, rowOptions, expectedOrder, optionLength, optionIndex, expectedOption, optionMatch, | |
| 4412 | + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ), | |
| 4413 | + rowLength = rows.length, | |
| 4414 | + fieldOptions = getFieldOptions( fieldId ), | |
| 4415 | + optionLength = fieldOptions.length; | |
| 4416 | + | |
| 4417 | + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) { | |
| 4418 | + row = rows[ rowIndex ]; | |
| 4419 | + opts = row.querySelector( '.frm_logic_field_opts' ); | |
| 4420 | + | |
| 4421 | + if ( opts.value != fieldId ) { | |
| 4422 | + continue; | |
| 4423 | + } | |
| 4424 | + | |
| 4425 | + logicId = row.id.split( '_' )[ 2 ]; | |
| 4426 | + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' ); | |
| 4427 | + | |
| 4428 | + for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) { | |
| 4429 | + expectedOption = fieldOptions[ optionIndex ]; | |
| 4430 | + optionMatch = valueSelect.querySelector( 'option[value="' + expectedOption + '"]' ); | |
| 4431 | + | |
| 4432 | + if ( optionMatch === null ) { | |
| 4433 | + optionMatch = document.createElement( 'option' ); | |
| 4434 | + optionMatch.setAttribute( 'value', expectedOption ); | |
| 4435 | + optionMatch.textContent = expectedOption; | |
| 4436 | + } | |
| 4437 | + | |
| 4438 | + valueSelect.prepend( optionMatch ); | |
| 4439 | + } | |
| 4440 | + | |
| 4441 | + optionMatch = valueSelect.querySelector( 'option[value=""]' ); | |
| 4442 | + if ( optionMatch !== null ) { | |
| 4443 | + valueSelect.prepend( optionMatch ); | |
| 4444 | + } | |
| 4445 | + } | |
| 4446 | + } | |
| 4447 | + | |
| 4448 | + function getFieldOptions( fieldId ) { | |
| 4449 | + var index, input, li, | |
| 4450 | + listItems = document.getElementById( 'frm_field_' + fieldId + '_opts' ).querySelectorAll( '.frm_single_option' ), | |
| 4451 | + options = [], | |
| 4452 | + length = listItems.length; | |
| 4453 | + for ( index = 0; index < length; index++ ) { | |
| 4454 | + li = listItems[ index ]; | |
| 4455 | + | |
| 4456 | + if ( li.classList.contains( 'frm_hidden' ) ) { | |
| 4457 | + continue; | |
| 4458 | + } | |
| 4459 | + | |
| 4460 | + input = li.querySelector( '.field_' + fieldId + '_option' ); | |
| 4461 | + options.push( input.value ); | |
| 4462 | + } | |
| 4463 | + return options; | |
| 4464 | + } | |
| 4465 | + | |
| 4466 | + function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) { | |
| 4467 | + var other, single, | |
| 4468 | + isOther = opt.key.indexOf( 'other' ) !== -1, | |
| 4469 | + | |
| 4470 | + id = 'field_' + fieldKey + '-' + opt.key; | |
| 4471 | + | |
| 4472 | + 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="" />'; | |
| 4473 | + | |
| 4474 | + single = '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id + | |
| 4475 | + '"><input type="' + type + | |
| 4476 | + '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) + | |
| 4477 | + '" value="' + opt.saved + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + opt.label + '</label>' + | |
| 4478 | + ( isOther ? other : '' ) + | |
| 4479 | + '</div>'; | |
| 4480 | + | |
| 4481 | + return single; | |
| 4482 | + } | |
| 4483 | + | |
| 4484 | + function fillDropdownOpts( field, atts ) { | |
| 4485 | + if ( field === null ) { | |
| 4486 | + return; | |
| 4487 | + } | |
| 4488 | + var sourceID = atts.sourceID, | |
| 4489 | + placeholder = atts.placeholder, | |
| 4490 | + isProduct = isProductField( sourceID ), | |
| 4491 | + showOther = atts.other; | |
| 4492 | + | |
| 4493 | + removeDropdownOpts( field ); | |
| 4494 | + var opts = getMultipleOpts( sourceID ), | |
| 4495 | + hasPlaceholder = ( typeof placeholder !== 'undefined' ); | |
| 4496 | + | |
| 4497 | + for ( var i = 0; i < opts.length; i++ ) { | |
| 4498 | + var label = opts[ i ].label, | |
| 4499 | + isOther = opts[ i ].key.indexOf( 'other' ) !== -1; | |
| 4500 | + | |
| 4501 | + if ( hasPlaceholder && label !== '' ) { | |
| 4502 | + addBlankSelectOption( field, placeholder ); | |
| 4503 | + } else if ( hasPlaceholder ) { | |
| 4504 | + label = placeholder; | |
| 4505 | + } | |
| 4506 | + hasPlaceholder = false; | |
| 4507 | + | |
| 4508 | + if ( ! isOther || showOther ) { | |
| 4509 | + var opt = document.createElement( 'option' ); | |
| 4510 | + opt.value = opts[ i ].saved; | |
| 4511 | + opt.innerHTML = label; | |
| 4512 | + | |
| 4513 | + if ( isProduct ) { | |
| 4514 | + opt.setAttribute( 'data-price', opts[ i ].price ); | |
| 4515 | + } | |
| 4516 | + | |
| 4517 | + field.appendChild( opt ); | |
| 4518 | + } | |
| 4519 | + } | |
| 4520 | + } | |
| 4521 | + | |
| 4522 | + function addBlankSelectOption( field, placeholder ) { | |
| 4523 | + var opt = document.createElement( 'option' ), | |
| 4524 | + firstChild = field.firstChild; | |
| 4525 | + | |
| 4526 | + opt.value = ''; | |
| 4527 | + opt.innerHTML = placeholder; | |
| 4528 | + if ( firstChild !== null ) { | |
| 4529 | + field.insertBefore( opt, firstChild ); | |
| 4530 | + field.selectedIndex = 0; | |
| 4531 | + } else { | |
| 4532 | + field.appendChild( opt ); | |
| 4533 | + } | |
| 4534 | + } | |
| 4535 | + | |
| 4536 | + function getMultipleOpts( fieldId ) { | |
| 4537 | + var i, saved, labelName, label, key, optObj, | |
| 4538 | + image, savedLabel, input, field, checkbox, fieldType, | |
| 4539 | + checked = false, | |
| 4540 | + opts = [], | |
| 4541 | + imageUrl = '', | |
| 4542 | + | |
| 4543 | + optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' ), | |
| 4544 | + separateValues = usingSeparateValues( fieldId ), | |
| 4545 | + hasImageOptions = imagesAsOptions( fieldId ), | |
| 4546 | + showLabelWithImage = showingLabelWithImage( fieldId ), | |
| 4547 | + isProduct = isProductField( fieldId ); | |
| 4548 | + | |
| 4549 | + for ( i = 0; i < optVals.length; i++ ) { | |
| 4550 | + 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 ) { | |
| 4551 | + continue; | |
| 4552 | + } | |
| 4553 | + saved = optVals[ i ].value; | |
| 4554 | + label = saved; | |
| 4555 | + key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' ); | |
| 4556 | + | |
| 4557 | + if ( separateValues ) { | |
| 4558 | + labelName = optVals[ i ].name.replace( '[label]', '[value]' ); | |
| 4559 | + saved = jQuery( 'input[name="' + labelName + '"]' ).val(); | |
| 4560 | + } | |
| 4561 | + | |
| 4562 | + if ( hasImageOptions ) { | |
| 4563 | + imageUrl = getImageUrlFromInput( optVals[i]); | |
| 4564 | + fieldType = radioOrCheckbox( fieldId ); | |
| 4565 | + label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType ); | |
| 4566 | + } | |
| 4567 | + | |
| 4568 | + checked = getChecked( optVals[ i ].id ); | |
| 4569 | + | |
| 4570 | + optObj = { | |
| 4571 | + saved: saved, | |
| 4572 | + label: label, | |
| 4573 | + checked: checked, | |
| 4574 | + key: key | |
| 4575 | + }; | |
| 4576 | + | |
| 4577 | + if ( isProduct ) { | |
| 4578 | + labelName = optVals[ i ].name.replace( '[label]', '[price]' ); | |
| 4579 | + optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val(); | |
| 4580 | + } | |
| 4581 | + | |
| 4582 | + opts.push( optObj ); | |
| 4583 | + } | |
| 4584 | + | |
| 4585 | + return opts; | |
| 4586 | + } | |
| 4587 | + | |
| 4588 | + function radioOrCheckbox( fieldId ) { | |
| 4589 | + var settings = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 4590 | + if ( settings === null ) { | |
| 4591 | + return 'radio'; | |
| 4592 | + } | |
| 4593 | + | |
| 4594 | + return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio'; | |
| 4595 | + } | |
| 4596 | + | |
| 4597 | + function getImageUrlFromInput( optVal ) { | |
| 4598 | + var img, | |
| 4599 | + wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' ); | |
| 4600 | + | |
| 4601 | + if ( ! wrapper.length ) { | |
| 4602 | + return ''; | |
| 4603 | + } | |
| 4604 | + | |
| 4605 | + img = wrapper.find( 'img' ); | |
| 4606 | + if ( ! img.length ) { | |
| 4607 | + return ''; | |
| 4608 | + } | |
| 4609 | + | |
| 4610 | + return img.attr( 'src' ); | |
| 4611 | + } | |
| 4612 | + | |
| 4613 | + function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) { | |
| 4614 | + var imageLabelClass, fullLabel, | |
| 4615 | + originalLabel = label, | |
| 4616 | + shape = fieldType === 'checkbox' ? 'square' : 'circle'; | |
| 4617 | + | |
| 4618 | + fullLabel = '<div class="frm_selected_checkmark"><svg class="frmsvg"><use xlink:href="#frm_checkmark_' + shape + '_icon"></svg></div>'; | |
| 4619 | + if ( imageUrl ) { | |
| 4620 | + fullLabel += '<img src="' + imageUrl + '" alt="' + originalLabel + '" />'; | |
| 4621 | + } else { | |
| 4622 | + fullLabel += '<div class="frm_empty_url">' + frm_admin_js.image_placeholder_icon + '</div>'; | |
| 4623 | + } | |
| 4624 | + if ( showLabelWithImage ) { | |
| 4625 | + fullLabel += '<span class="frm_text_label_for_image"><span class="frm_text_label_for_image_inner">' + originalLabel + '</span></span>'; | |
| 4626 | + } | |
| 4627 | + | |
| 4628 | + imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : ''; | |
| 4629 | + | |
| 4630 | + return ( '<span class="frm_image_option_container' + imageLabelClass + '">' + fullLabel + '</span>' ); | |
| 4631 | + } | |
| 4632 | + | |
| 4633 | + function getChecked( id ) { | |
| 4634 | + field = jQuery( '#' + id ); | |
| 4635 | + | |
| 4636 | + if ( field.length === 0 ) { | |
| 4637 | + return false; | |
| 4638 | + } | |
| 4639 | + | |
| 4640 | + checkbox = field.siblings( 'input[type=checkbox]' ); | |
| 4641 | + | |
| 4642 | + return checkbox.length && checkbox.prop( 'checked' ); | |
| 4643 | + } | |
| 4644 | + | |
| 4645 | + function removeDropdownOpts( field ) { | |
| 4646 | + var i; | |
| 4647 | + if ( typeof field.options === 'undefined' ) { | |
| 4648 | + return; | |
| 4649 | + } | |
| 4650 | + | |
| 4651 | + for ( i = field.options.length - 1; i >= 0; i-- ) { | |
| 4652 | + field.remove( i ); | |
| 4653 | + } | |
| 4654 | + } | |
| 4655 | + | |
| 4656 | + /** | |
| 4657 | + * Is the box checked to use separate values? | |
| 4658 | + */ | |
| 4659 | + function usingSeparateValues( fieldId ) { | |
| 4660 | + return isChecked( 'separate_value_' + fieldId ); | |
| 4661 | + } | |
| 4662 | + | |
| 4663 | + /** | |
| 4664 | + * Is the box checked to use images as options? | |
| 4665 | + */ | |
| 4666 | + function imagesAsOptions( fieldId ) { | |
| 4667 | + return isChecked( 'image_options_' + fieldId ); | |
| 4668 | + } | |
| 4669 | + | |
| 4670 | + function showingLabelWithImage( fieldId ) { | |
| 4671 | + return ! isChecked( 'hide_image_text_' + fieldId ); | |
| 4672 | + } | |
| 4673 | + | |
| 4674 | + function isChecked( id ) { | |
| 4675 | + var field = document.getElementById( id ); | |
| 4676 | + if ( field === null ) { | |
| 4677 | + return false; | |
| 4678 | + } else { | |
| 4679 | + return field.checked; | |
| 4680 | + } | |
| 4681 | + } | |
| 4682 | + | |
| 4683 | + /* TODO: Is this still used? */ | |
| 4684 | + function checkUniqueOpt( id, text ) { | |
| 4685 | + if ( id.indexOf( 'field_key_' ) === 0 ) { | |
| 4686 | + var a = id.split( '-' ); | |
| 4687 | + jQuery.each( jQuery( 'label[id^="' + a[0] + '"]' ), function( k, v ) { | |
| 4688 | + var c = false; | |
| 4689 | + if ( ! c && jQuery( v ).attr( 'id' ) != id && jQuery( v ).html() == text ) { | |
| 4690 | + c = true; | |
| 4691 | + infoModal( 'Saved values cannot be identical.' ); | |
| 4692 | + } | |
| 4693 | + }); | |
| 4694 | + } | |
| 4695 | + } | |
| 4696 | + | |
| 4697 | + function setStarValues() { | |
| 4698 | + /*jshint validthis:true */ | |
| 4699 | + var fieldID = this.id.replace( 'radio_maxnum_', '' ); | |
| 4700 | + var container = jQuery( '#field_' + fieldID + '_inner_container .frm-star-group' ); | |
| 4701 | + var fieldKey = document.getElementsByName( 'field_options[field_key_' + fieldID + ']' )[0].value; | |
| 4702 | + container.html( '' ); | |
| 4703 | + | |
| 4704 | + var min = 1; | |
| 4705 | + var max = this.value; | |
| 4706 | + if ( min > max ) { | |
| 4707 | + max = min; | |
| 4708 | + } | |
| 4709 | + | |
| 4710 | + for ( var i = min; i <= max; i++ ) { | |
| 4711 | + 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>' ); | |
| 4712 | + } | |
| 4713 | + } | |
| 4714 | + | |
| 4715 | + function setScaleValues() { | |
| 4716 | + /*jshint validthis:true */ | |
| 4717 | + var isMin = this.id.indexOf( 'minnum' ) !== -1; | |
| 4718 | + var fieldID = this.id.replace( 'scale_maxnum_', '' ).replace( 'scale_minnum_', '' ); | |
| 4719 | + var min = this.value; | |
| 4720 | + var max = this.value; | |
| 4721 | + if ( isMin ) { | |
| 4722 | + max = document.getElementById( 'scale_maxnum_' + fieldID ).value; | |
| 4723 | + } else { | |
| 4724 | + min = document.getElementById( 'scale_minnum_' + fieldID ).value; | |
| 4725 | + } | |
| 4726 | + | |
| 4727 | + updateScaleValues( parseInt( min, 10 ), parseInt( max, 10 ), fieldID ); | |
| 4728 | + } | |
| 4729 | + | |
| 4730 | + function updateScaleValues( min, max, fieldID ) { | |
| 4731 | + var container = jQuery( '#field_' + fieldID + '_inner_container .frm_form_fields' ); | |
| 4732 | + container.html( '' ); | |
| 4733 | + | |
| 4734 | + if ( min >= max ) { | |
| 4735 | + max = min + 1; | |
| 4736 | + } | |
| 4737 | + | |
| 4738 | + for ( var i = min; i <= max; i++ ) { | |
| 4739 | + container.append( '<div class="frm_scale"><label><input type="hidden" name="field_options[options_' + fieldID + '][' + i + ']" value="' + i + '"> <input type="radio" name="item_meta[' + fieldID + ']" value="' + i + '"> ' + i + ' </label></div>' ); | |
| 4740 | + } | |
| 4741 | + container.append( '<div class="clear"></div>' ); | |
| 4742 | + } | |
| 4743 | + | |
| 4744 | + function getFieldValues() { | |
| 4745 | + /*jshint validthis:true */ | |
| 4746 | + var isTaxonomy, | |
| 4747 | + val = this.value; | |
| 4748 | + | |
| 4749 | + if ( val ) { | |
| 4750 | + var parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' ); | |
| 4751 | + var fieldID = parentIDs[0]; | |
| 4752 | + var metaKey = parentIDs[1]; | |
| 4753 | + var valueField = document.getElementById( 'frm_field_id_' + val ); | |
| 4754 | + var valueFieldType = valueField.getAttribute( 'data-ftype' ); | |
| 4755 | + var fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey ); | |
| 4756 | + var optionName = 'field_options[hide_opt_' + fieldID + '][]'; | |
| 4757 | + var optionID = 'frm_field_logic_opt_' + fieldID; | |
| 4758 | + var input = false; | |
| 4759 | + var showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' ); | |
| 4760 | + var showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' ); | |
| 4761 | + | |
| 4762 | + if ( showSelect ) { | |
| 4763 | + isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val ); | |
| 4764 | + if ( isTaxonomy !== null ) { | |
| 4765 | + // get the category options with ajax | |
| 4766 | + showSelect = false; | |
| 4767 | + } | |
| 4768 | + } | |
| 4769 | + | |
| 4770 | + if ( showSelect || showText ) { | |
| 4771 | + fill.innerHTML = ''; | |
| 4772 | + if ( showSelect ) { | |
| 4773 | + input = document.createElement( 'select' ); | |
| 4774 | + } else { | |
| 4775 | + input = document.createElement( 'input' ); | |
| 4776 | + input.type = 'text'; | |
| 4777 | + } | |
| 4778 | + input.name = optionName; | |
| 4779 | + input.id = optionID + '_' + metaKey; | |
| 4780 | + fill.appendChild( input ); | |
| 4781 | + | |
| 4782 | + if ( showSelect ) { | |
| 4783 | + var fillField = document.getElementById( input.id ); | |
| 4784 | + fillDropdownOpts( fillField, { | |
| 4785 | + sourceID: val, | |
| 4786 | + placeholder: '', | |
| 4787 | + other: true | |
| 4788 | + }); | |
| 4789 | + } | |
| 4790 | + } else { | |
| 4791 | + var thisType = this.getAttribute( 'data-type' ); | |
| 4792 | + frmGetFieldValues( val, fieldID, metaKey, thisType ); | |
| 4793 | + } | |
| 4794 | + } | |
| 4795 | + } | |
| 4796 | + | |
| 4797 | + function getFieldSelection() { | |
| 4798 | + /*jshint validthis:true */ | |
| 4799 | + var formId = this.value; | |
| 4800 | + if ( formId ) { | |
| 4801 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 4802 | + getTaxOrFieldSelection( formId, fieldId ); | |
| 4803 | + } | |
| 4804 | + } | |
| 4805 | + | |
| 4806 | + function getTaxOrFieldSelection( formId, fieldId ) { | |
| 4807 | + if ( formId ) { | |
| 4808 | + jQuery.ajax({ | |
| 4809 | + type: 'POST', | |
| 4810 | + url: ajaxurl, | |
| 4811 | + data: { | |
| 4812 | + action: 'frm_get_field_selection', | |
| 4813 | + field_id: fieldId, | |
| 4814 | + form_id: formId, | |
| 4815 | + nonce: frmGlobal.nonce | |
| 4816 | + }, | |
| 4817 | + success: function( msg ) { | |
| 4818 | + jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show(); | |
| 4819 | + } | |
| 4820 | + }); | |
| 4821 | + } | |
| 4822 | + } | |
| 4823 | + | |
| 4824 | + function updateFieldOrder() { | |
| 4825 | + var fields, fieldId, field, currentOrder, newOrder; | |
| 4826 | + renumberPageBreaks(); | |
| 4827 | + jQuery( '#frm-show-fields' ).each( function( i ) { | |
| 4828 | + fields = jQuery( 'li.frm_field_box', this ); | |
| 4829 | + for ( i = 0; i < fields.length; i++ ) { | |
| 4830 | + fieldId = fields[ i ].getAttribute( 'data-fid' ); | |
| 4831 | + field = jQuery( 'input[name="field_options[field_order_' + fieldId + ']"]' ); | |
| 4832 | + currentOrder = field.val(); | |
| 4833 | + newOrder = i + 1; | |
| 4834 | + | |
| 4835 | + if ( currentOrder != newOrder ) { | |
| 4836 | + field.val( newOrder ); | |
| 4837 | + singleField = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 4838 | + | |
| 4839 | + moveFieldSettings( singleField ); | |
| 4840 | + fieldUpdated(); | |
| 4841 | + } | |
| 4842 | + } | |
| 4843 | + }); | |
| 4844 | + } | |
| 4845 | + | |
| 4846 | + function toggleSectionHolder() { | |
| 4847 | + document.querySelectorAll( '.start_divider' ).forEach( | |
| 4848 | + function( divider ) { | |
| 4849 | + toggleOneSectionHolder( jQuery( divider ) ); | |
| 4850 | + } | |
| 4851 | + ); | |
| 4852 | + } | |
| 4853 | + | |
| 4854 | + function toggleOneSectionHolder( $section ) { | |
| 4855 | + var noSectionFields, $rows, length, index, sectionHasFields; | |
| 4856 | + | |
| 4857 | + if ( ! $section.length ) { | |
| 4858 | + return; | |
| 4859 | + } | |
| 4860 | + | |
| 4861 | + $rows = $section.find( 'ul.frm_sorting' ); | |
| 4862 | + sectionHasFields = false; | |
| 4863 | + length = $rows.length; | |
| 4864 | + for ( index = 0; index < length; ++index ) { | |
| 4865 | + if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) { | |
| 4866 | + sectionHasFields = true; | |
| 4867 | + break; | |
| 4868 | + } | |
| 4869 | + } | |
| 4870 | + | |
| 4871 | + noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 ); | |
| 4872 | + noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields ); | |
| 4873 | + } | |
| 4874 | + | |
| 4875 | + function slideDown() { | |
| 4876 | + /*jshint validthis:true */ | |
| 4877 | + var id = jQuery( this ).data( 'slidedown' ); | |
| 4878 | + var $thisId = jQuery( document.getElementById( id ) ); | |
| 4879 | + if ( $thisId.is( ':hidden' ) ) { | |
| 4880 | + $thisId.slideDown( 'fast' ); | |
| 4881 | + this.style.display = 'none'; | |
| 4882 | + } | |
| 4883 | + return false; | |
| 4884 | + } | |
| 4885 | + | |
| 4886 | + function slideUp() { | |
| 4887 | + /*jshint validthis:true */ | |
| 4888 | + var id = jQuery( this ).data( 'slideup' ); | |
| 4889 | + var $thisId = jQuery( document.getElementById( id ) ); | |
| 4890 | + $thisId.slideUp( 'fast' ); | |
| 4891 | + $thisId.siblings( 'a' ).show(); | |
| 4892 | + return false; | |
| 4893 | + } | |
| 4894 | + | |
| 4895 | + function adjustVisibilityValuesForEveryoneValues( element, option ) { | |
| 4896 | + if ( '' === option.getAttribute( 'value' ) ) { | |
| 4897 | + onEveryoneOptionSelected( jQuery( this ) ); | |
| 4898 | + } else { | |
| 4899 | + unselectEveryoneOptionIfSelected( jQuery( this ) ); | |
| 4900 | + } | |
| 4901 | + } | |
| 4902 | + | |
| 4903 | + function onEveryoneOptionSelected( $select ) { | |
| 4904 | + $select.val( '' ); | |
| 4905 | + $select.next( '.btn-group' ).find( '.multiselect-container li input[value!=""]' ).prop( 'checked', false ); | |
| 4906 | + } | |
| 4907 | + | |
| 4908 | + function unselectEveryoneOptionIfSelected( $select ) { | |
| 4909 | + var selectedValues = $select.val(), | |
| 4910 | + index; | |
| 4911 | + | |
| 4912 | + if ( selectedValues === null ) { | |
| 4913 | + $select.next( '.btn-group' ).find( '.multiselect-container li input[value=""]' ).prop( 'checked', true ); | |
| 4914 | + onEveryoneOptionSelected( $select ); | |
| 4915 | + return; | |
| 4916 | + } | |
| 4917 | + | |
| 4918 | + index = selectedValues.indexOf( '' ); | |
| 4919 | + if ( index >= 0 ) { | |
| 4920 | + selectedValues.splice( index, 1 ); | |
| 4921 | + $select.val( selectedValues ); | |
| 4922 | + $select.next( '.btn-group' ).find( '.multiselect-container li input[value=""]' ).prop( 'checked', false ); | |
| 4923 | + } | |
| 4924 | + } | |
| 4925 | + | |
| 4926 | + /** | |
| 4927 | + * Get rid of empty container that inserts extra space. | |
| 4928 | + */ | |
| 4929 | + function hideEmptyEle() { | |
| 4930 | + jQuery( '.frm-hide-empty' ).each( function() { | |
| 4931 | + if ( jQuery( this ).text().trim().length === 0 ) { | |
| 4932 | + jQuery( this ).remove(); | |
| 4933 | + } | |
| 4934 | + }); | |
| 4935 | + } | |
| 4936 | + | |
| 4937 | + /* Change the classes in the builder */ | |
| 4938 | + function changeFieldClass( field, setting ) { | |
| 4939 | + var classes, replace, alignField, | |
| 4940 | + replaceWith = ' ' + setting.value, | |
| 4941 | + fieldId = field.getAttribute( 'data-fid' ); | |
| 4942 | + | |
| 4943 | + // Include classes from multiple settings. | |
| 4944 | + if ( typeof fieldId !== 'undefined' ) { | |
| 4945 | + if ( setting.classList.contains( 'field_options_align' ) ) { | |
| 4946 | + replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value; | |
| 4947 | + } else if ( setting.classList.contains( 'frm_classes' ) ) { | |
| 4948 | + alignField = document.getElementById( 'field_options_align_' + fieldId ); | |
| 4949 | + if ( alignField !== null ) { | |
| 4950 | + replaceWith += ' ' + alignField.value; | |
| 4951 | + } | |
| 4952 | + } | |
| 4953 | + } | |
| 4954 | + replaceWith += ' '; | |
| 4955 | + | |
| 4956 | + // Allow for the column number dropdown. | |
| 4957 | + replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' ).replace( ' frm_alignright ', ' ' ); | |
| 4958 | + | |
| 4959 | + classes = field.className.split( ' frmstart ' )[1]; | |
| 4960 | + classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0]; | |
| 4961 | + | |
| 4962 | + if ( classes.trim() === '' ) { | |
| 4963 | + replace = ' frmstart frmend '; | |
| 4964 | + if ( -1 === field.className.indexOf( replace ) ) { | |
| 4965 | + replace = ' frmstart frmend '; | |
| 4966 | + } | |
| 4967 | + replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend '; | |
| 4968 | + } else { | |
| 4969 | + replace = classes.trim(); | |
| 4970 | + replaceWith = replaceWith.trim(); | |
| 4971 | + } | |
| 4972 | + | |
| 4973 | + field.className = field.className.replace( replace, replaceWith ); | |
| 4974 | + } | |
| 4975 | + | |
| 4976 | + function maybeShowInlineModal( e ) { | |
| 4977 | + /*jshint validthis:true */ | |
| 4978 | + e.preventDefault(); | |
| 4979 | + showInlineModal( this ); | |
| 4980 | + } | |
| 4981 | + | |
| 4982 | + function showInlineModal( icon, input ) { | |
| 4983 | + var box = document.getElementById( icon.getAttribute( 'data-open' ) ), | |
| 4984 | + container = jQuery( icon ).closest( 'p' ), | |
| 4985 | + inputTrigger = ( typeof input !== 'undefined' ); | |
| 4986 | + | |
| 4987 | + if ( container.hasClass( 'frm-open' ) ) { | |
| 4988 | + container.removeClass( 'frm-open' ); | |
| 4989 | + box.classList.add( 'frm_hidden' ); | |
| 4990 | + } else { | |
| 4991 | + if ( ! inputTrigger ) { | |
| 4992 | + input = getInputForIcon( icon ); | |
| 4993 | + } | |
| 4994 | + if ( input !== null ) { | |
| 4995 | + if ( ! inputTrigger ) { | |
| 4996 | + input.focus(); | |
| 4997 | + } | |
| 4998 | + container.after( box ); | |
| 4999 | + box.setAttribute( 'data-fills', input.id ); | |
| 5000 | + | |
| 5001 | + if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) { | |
| 5002 | + popCalcFields( box, true ); | |
| 5003 | + } | |
| 5004 | + } | |
| 5005 | + | |
| 5006 | + container.addClass( 'frm-open' ); | |
| 5007 | + box.classList.remove( 'frm_hidden' ); | |
| 5008 | + } | |
| 5009 | + } | |
| 5010 | + | |
| 5011 | + function dismissInlineModal( e ) { | |
| 5012 | + /*jshint validthis:true */ | |
| 5013 | + e.preventDefault(); | |
| 5014 | + this.parentNode.classList.add( 'frm_hidden' ); | |
| 5015 | + jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' ); | |
| 5016 | + } | |
| 5017 | + | |
| 5018 | + function changeInputtedValue() { | |
| 5019 | + /*jshint validthis:true */ | |
| 5020 | + var i, | |
| 5021 | + action = this.getAttribute( 'data-frmchange' ).split( ',' ); | |
| 5022 | + | |
| 5023 | + for ( i = 0; i < action.length; i++ ) { | |
| 5024 | + if ( action[i] === 'updateOption' ) { | |
| 5025 | + changeHiddenSeparateValue( this ); | |
| 5026 | + } else if ( action[i] === 'updateDefault' ) { | |
| 5027 | + changeDefaultRadioValue( this ); | |
| 5028 | + } else { | |
| 5029 | + this.value = this.value[ action[i] ](); | |
| 5030 | + } | |
| 5031 | + } | |
| 5032 | + } | |
| 5033 | + | |
| 5034 | + /** | |
| 5035 | + * When the saved value is changed, update the default value radio. | |
| 5036 | + */ | |
| 5037 | + function changeDefaultRadioValue( input ) { | |
| 5038 | + var parentLi = getOptionParent( input ), | |
| 5039 | + key = parentLi.getAttribute( 'data-optkey' ), | |
| 5040 | + fieldId = getOptionFieldId( parentLi, key ), | |
| 5041 | + defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' ); | |
| 5042 | + | |
| 5043 | + if ( defaultRadio !== null ) { | |
| 5044 | + defaultRadio.value = input.value; | |
| 5045 | + } | |
| 5046 | + } | |
| 5047 | + | |
| 5048 | + /** | |
| 5049 | + * If separate values are not enabled, change the saved value when | |
| 5050 | + * the displayed value is changed. | |
| 5051 | + */ | |
| 5052 | + function changeHiddenSeparateValue( input ) { | |
| 5053 | + var savedVal, | |
| 5054 | + parentLi = getOptionParent( input ), | |
| 5055 | + key = parentLi.getAttribute( 'data-optkey' ), | |
| 5056 | + fieldId = getOptionFieldId( parentLi, key ), | |
| 5057 | + sep = document.getElementById( 'separate_value_' + fieldId ); | |
| 5058 | + | |
| 5059 | + if ( sep !== null && sep.checked === false ) { | |
| 5060 | + // If separate values are not turned on. | |
| 5061 | + savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key ); | |
| 5062 | + savedVal.value = input.value; | |
| 5063 | + changeDefaultRadioValue( savedVal ); | |
| 5064 | + } | |
| 5065 | + } | |
| 5066 | + | |
| 5067 | + function getOptionParent( input ) { | |
| 5068 | + var parentLi = input.parentNode; | |
| 5069 | + if ( parentLi.tagName !== 'LI' ) { | |
| 5070 | + parentLi = parentLi.parentNode; | |
| 5071 | + } | |
| 5072 | + return parentLi; | |
| 5073 | + } | |
| 5074 | + | |
| 5075 | + function getOptionFieldId( li, key ) { | |
| 5076 | + var liId = li.id; | |
| 5077 | + | |
| 5078 | + return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' ); | |
| 5079 | + } | |
| 5080 | + | |
| 5081 | + function submitBuild() { | |
| 5082 | + /*jshint validthis:true */ | |
| 5083 | + var $thisEle = jQuery( this ); | |
| 5084 | + var p = $thisEle.html(); | |
| 5085 | + | |
| 5086 | + preFormSave( this ); | |
| 5087 | + | |
| 5088 | + var $form = jQuery( builderForm ); | |
| 5089 | + var v = JSON.stringify( $form.serializeArray() ); | |
| 5090 | + | |
| 5091 | + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v ); | |
| 5092 | + jQuery.ajax({ | |
| 5093 | + type: 'POST', | |
| 5094 | + url: ajaxurl, | |
| 5095 | + data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce}, | |
| 5096 | + success: function( msg ) { | |
| 5097 | + afterFormSave( $thisEle, p ); | |
| 5098 | + | |
| 5099 | + var $postStuff = document.getElementById( 'post-body-content' ); | |
| 5100 | + var $html = document.createElement( 'div' ); | |
| 5101 | + $html.setAttribute( 'class', 'frm_updated_message' ); | |
| 5102 | + $html.innerHTML = msg; | |
| 5103 | + $postStuff.insertBefore( $html, $postStuff.firstChild ); | |
| 5104 | + }, | |
| 5105 | + error: function() { | |
| 5106 | + triggerSubmit( document.getElementById( 'frm_js_build_form' ) ); | |
| 5107 | + } | |
| 5108 | + }); | |
| 5109 | + } | |
| 5110 | + | |
| 5111 | + function triggerSubmit( form ) { | |
| 5112 | + var button = form.ownerDocument.createElement( 'input' ); | |
| 5113 | + button.style.display = 'none'; | |
| 5114 | + button.type = 'submit'; | |
| 5115 | + form.appendChild( button ).click(); | |
| 5116 | + form.removeChild( button ); | |
| 5117 | + } | |
| 5118 | + | |
| 5119 | + function triggerChange( element ) { | |
| 5120 | + jQuery( element ).trigger( 'change' ); | |
| 5121 | + } | |
| 5122 | + | |
| 5123 | + function submitNoAjax() { | |
| 5124 | + /*jshint validthis:true */ | |
| 5125 | + var form; | |
| 5126 | + | |
| 5127 | + preFormSave( this ); | |
| 5128 | + form = jQuery( builderForm ); | |
| 5129 | + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) ); | |
| 5130 | + triggerSubmit( document.getElementById( 'frm_js_build_form' ) ); | |
| 5131 | + } | |
| 5132 | + | |
| 5133 | + function preFormSave( b ) { | |
| 5134 | + removeWPUnload(); | |
| 5135 | + if ( jQuery( 'form.inplace_form' ).length ) { | |
| 5136 | + jQuery( '.inplace_save, .postbox' ).trigger( 'click' ); | |
| 5137 | + } | |
| 5138 | + | |
| 5139 | + $button = jQuery( b ); | |
| 5140 | + | |
| 5141 | + if ( $button.hasClass( 'frm_button_submit' ) ) { | |
| 5142 | + $button.addClass( 'frm_loading_form' ); | |
| 5143 | + $button.html( frm_admin_js.saving ); | |
| 5144 | + } else { | |
| 5145 | + $button.addClass( 'frm_loading_button' ); | |
| 5146 | + $button.val( frm_admin_js.saving ); | |
| 5147 | + } | |
| 5148 | + } | |
| 5149 | + | |
| 5150 | + function afterFormSave( $button, buttonVal ) { | |
| 5151 | + $button.removeClass( 'frm_loading_form' ).removeClass( 'frm_loading_button' ); | |
| 5152 | + $button.html( frm_admin_js.saved ); | |
| 5153 | + resetOptionTextDetails(); | |
| 5154 | + fieldsUpdated = 0; | |
| 5155 | + | |
| 5156 | + setTimeout( function() { | |
| 5157 | + jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() { | |
| 5158 | + this.parentNode.removeChild( this ); | |
| 5159 | + }); | |
| 5160 | + $button.fadeOut( 'slow', function() { | |
| 5161 | + $button.html( buttonVal ); | |
| 5162 | + $button.show(); | |
| 5163 | + }); | |
| 5164 | + }, 5000 ); | |
| 5165 | + } | |
| 5166 | + | |
| 5167 | + function initUpgradeModal() { | |
| 5168 | + var $info = initModal( '#frm_upgrade_modal' ); | |
| 5169 | + if ( $info === false ) { | |
| 5170 | + return; | |
| 5171 | + } | |
| 5172 | + | |
| 5173 | + jQuery( document ).on( 'click', '[data-upgrade]', function( event ) { | |
| 5174 | + var upgradeLabel, requires, button, link, content; | |
| 5175 | + | |
| 5176 | + event.preventDefault(); | |
| 5177 | + upgradeLabel = this.getAttribute( 'data-upgrade' ); | |
| 5178 | + | |
| 5179 | + if ( '' === upgradeLabel ) { | |
| 5180 | + // if the upgrade level is empty, it's because this upgrade is already active. | |
| 5181 | + return; | |
| 5182 | + } | |
| 5183 | + | |
| 5184 | + jQuery( '#frm_upgrade_modal .frm_lock_icon' ).removeClass( 'frm_lock_open_icon' ); | |
| 5185 | + jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_icon' ); | |
| 5186 | + | |
| 5187 | + requires = this.getAttribute( 'data-requires' ); | |
| 5188 | + if ( typeof requires === 'undefined' || requires === null || requires === '' ) { | |
| 5189 | + requires = 'Pro'; | |
| 5190 | + } | |
| 5191 | + jQuery( '.license-level' ).text( requires ); | |
| 5192 | + | |
| 5193 | + // If one click upgrade, hide other content | |
| 5194 | + addOneClickModal( this ); | |
| 5195 | + | |
| 5196 | + jQuery( '.frm_feature_label' ).text( upgradeLabel ); | |
| 5197 | + jQuery( '#frm_upgrade_modal h2' ).show(); | |
| 5198 | + | |
| 5199 | + $info.dialog( 'open' ); | |
| 5200 | + | |
| 5201 | + // set the utm medium | |
| 5202 | + button = $info.find( '.button-primary:not(#frm-oneclick-button)' ); | |
| 5203 | + link = button.attr( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + this.getAttribute( 'data-medium' ) ); | |
| 5204 | + content = this.getAttribute( 'data-content' ); | |
| 5205 | + if ( content === undefined ) { | |
| 5206 | + content = ''; | |
| 5207 | + } | |
| 5208 | + link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content ); | |
| 5209 | + button.attr( 'href', link ); | |
| 5210 | + return false; | |
| 5211 | + }); | |
| 5212 | + } | |
| 5213 | + | |
| 5214 | + /** | |
| 5215 | + * Allow addons to be installed from the upgrade modal. | |
| 5216 | + */ | |
| 5217 | + function addOneClickModal( link ) { | |
| 5218 | + var oneclickMessage = document.getElementById( 'frm-oneclick' ), | |
| 5219 | + oneclick = link.getAttribute( 'data-oneclick' ), | |
| 5220 | + customLink = link.getAttribute( 'data-link' ), | |
| 5221 | + showLink = document.getElementById( 'frm-upgrade-modal-link' ), | |
| 5222 | + upgradeMessage = document.getElementById( 'frm-upgrade-message' ), | |
| 5223 | + newMessage = link.getAttribute( 'data-message' ), | |
| 5224 | + button = document.getElementById( 'frm-oneclick-button' ), | |
| 5225 | + showIt = 'block', | |
| 5226 | + hideIt = 'none'; | |
| 5227 | + | |
| 5228 | + // If one click upgrade, hide other content. | |
| 5229 | + if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) { | |
| 5230 | + showIt = 'none'; | |
| 5231 | + hideIt = 'block'; | |
| 5232 | + oneclick = JSON.parse( oneclick ); | |
| 5233 | + | |
| 5234 | + button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' ); | |
| 5235 | + button.className = button.className + ' ' + oneclick.class; | |
| 5236 | + button.rel = oneclick.url; | |
| 5237 | + } | |
| 5238 | + | |
| 5239 | + // Use a custom message in the modal. | |
| 5240 | + if ( newMessage === null || typeof newMessage === 'undefined' || newMessage === '' ) { | |
| 5241 | + newMessage = upgradeMessage.getAttribute( 'data-default' ); | |
| 5242 | + } | |
| 5243 | + upgradeMessage.innerHTML = newMessage; | |
| 5244 | + | |
| 5245 | + // Either set the link or use the default. | |
| 5246 | + if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) { | |
| 5247 | + customLink = showLink.getAttribute( 'data-default' ); | |
| 5248 | + } | |
| 5249 | + showLink.href = customLink; | |
| 5250 | + | |
| 5251 | + document.getElementById( 'frm-addon-status' ).style.display = 'none'; | |
| 5252 | + oneclickMessage.style.display = hideIt; | |
| 5253 | + button.style.display = hideIt === 'block' ? 'inline-block' : hideIt; | |
| 5254 | + upgradeMessage.style.display = showIt; | |
| 5255 | + showLink.style.display = showIt === 'block' ? 'inline-block' : showIt; | |
| 5256 | + } | |
| 5257 | + | |
| 5258 | + /* Form settings */ | |
| 5259 | + | |
| 5260 | + function showInputIcon( parentClass ) { | |
| 5261 | + if ( typeof parentClass === 'undefined' ) { | |
| 5262 | + parentClass = ''; | |
| 5263 | + } | |
| 5264 | + maybeAddFieldSelection( parentClass ); | |
| 5265 | + 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>' ); | |
| 5266 | + } | |
| 5267 | + | |
| 5268 | + /** | |
| 5269 | + * For reverse compatibility. Check for fields that were | |
| 5270 | + * using the old sidebar. | |
| 5271 | + */ | |
| 5272 | + function maybeAddFieldSelection( parentClass ) { | |
| 5273 | + var i, | |
| 5274 | + 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' ); | |
| 5275 | + for ( i = 0; i < missingClass.length; i++ ) { | |
| 5276 | + missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' ); | |
| 5277 | + } | |
| 5278 | + } | |
| 5279 | + | |
| 5280 | + function showSuccessOpt() { | |
| 5281 | + /*jshint validthis:true */ | |
| 5282 | + var c = 'success'; | |
| 5283 | + if ( this.name === 'options[edit_action]' ) { | |
| 5284 | + c = 'edit'; | |
| 5285 | + } | |
| 5286 | + var v = jQuery( this ).val(); | |
| 5287 | + jQuery( '.' + c + '_action_box' ).hide(); | |
| 5288 | + if ( v === 'redirect' ) { | |
| 5289 | + jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 5290 | + } else if ( v === 'page' ) { | |
| 5291 | + jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 5292 | + } else { | |
| 5293 | + jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 5294 | + } | |
| 5295 | + } | |
| 5296 | + | |
| 5297 | + function copyFormAction() { | |
| 5298 | + /*jshint validthis:true */ | |
| 5299 | + if ( waitForActionToLoadBeforeCopy( this ) ) { | |
| 5300 | + return; | |
| 5301 | + } | |
| 5302 | + | |
| 5303 | + var action = jQuery( this ).closest( '.frm_form_action_settings' ).clone(); | |
| 5304 | + var currentID = action.attr( 'id' ).replace( 'frm_form_action_', '' ); | |
| 5305 | + var newID = newActionId( currentID ); | |
| 5306 | + action.find( '.frm_action_id, .frm-btn-group' ).remove(); | |
| 5307 | + action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' ); | |
| 5308 | + action.find( '.widget-inside' ).hide(); | |
| 5309 | + | |
| 5310 | + // the .html() gets original values, so they need to be set | |
| 5311 | + action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() { | |
| 5312 | + return this.value; | |
| 5313 | + }); | |
| 5314 | + | |
| 5315 | + action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() { | |
| 5316 | + return this.checked; | |
| 5317 | + }); | |
| 5318 | + | |
| 5319 | + var rename = new RegExp( '\\[' + currentID + '\\]', 'g' ); | |
| 5320 | + var reid = new RegExp( '_' + currentID + '"', 'g' ); | |
| 5321 | + var reclass = new RegExp( '-' + currentID + '"', 'g' ); | |
| 5322 | + var revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble | |
| 5323 | + | |
| 5324 | + var html = action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' ); | |
| 5325 | + html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' ); | |
| 5326 | + var div = '<div id="frm_form_action_' + newID + '" class="widget frm_form_action_settings frm_single_email_settings" data-actionkey="' + newID + '">'; | |
| 5327 | + | |
| 5328 | + jQuery( '#frm_notification_settings' ).append( div + html + '</div>' ); | |
| 5329 | + initiateMultiselect(); | |
| 5330 | + } | |
| 5331 | + | |
| 5332 | + function waitForActionToLoadBeforeCopy( element ) { | |
| 5333 | + var $trigger = jQuery( element ), | |
| 5334 | + $original = $trigger.closest( '.frm_form_action_settings' ), | |
| 5335 | + $inside = $original.find( '.widget-inside' ), | |
| 5336 | + $top; | |
| 5337 | + | |
| 5338 | + if ( $inside.find( 'p, div, table' ).length ) { | |
| 5339 | + return false; | |
| 5340 | + } | |
| 5341 | + | |
| 5342 | + $top = $original.find( '.widget-top' ); | |
| 5343 | + $top.on( 'frm-action-loaded', function() { | |
| 5344 | + $trigger.trigger( 'click' ); | |
| 5345 | + $original.removeClass( 'open' ); | |
| 5346 | + $inside.hide(); | |
| 5347 | + }); | |
| 5348 | + $top.trigger( 'click' ); | |
| 5349 | + return true; | |
| 5350 | + } | |
| 5351 | + | |
| 5352 | + function newActionId( currentID ) { | |
| 5353 | + var newID = parseInt( currentID, 10 ) + 11; | |
| 5354 | + var exists = document.getElementById( 'frm_form_action_' + newID ); | |
| 5355 | + if ( exists !== null ) { | |
| 5356 | + newID++; | |
| 5357 | + newID = newActionId( newID ); | |
| 5358 | + } | |
| 5359 | + return newID; | |
| 5360 | + } | |
| 5361 | + | |
| 5362 | + function addFormAction() { | |
| 5363 | + /*jshint validthis:true */ | |
| 5364 | + var type, actionId, formId, placeholderSetting, actionsList; | |
| 5365 | + | |
| 5366 | + type = jQuery( this ).data( 'actiontype' ); | |
| 5367 | + | |
| 5368 | + if ( isAtLimitForActionType( type ) ) { | |
| 5369 | + return; | |
| 5370 | + } | |
| 5371 | + | |
| 5372 | + actionId = getNewActionId(); | |
| 5373 | + formId = thisFormId; | |
| 5374 | + | |
| 5375 | + placeholderSetting = document.createElement( 'div' ); | |
| 5376 | + placeholderSetting.classList.add( 'frm_single_' + type + '_settings' ); | |
| 5377 | + | |
| 5378 | + actionsList = document.getElementById( 'frm_notification_settings' ); | |
| 5379 | + actionsList.appendChild( placeholderSetting ); | |
| 5380 | + | |
| 5381 | + jQuery.ajax({ | |
| 5382 | + type: 'POST', | |
| 5383 | + url: ajaxurl, | |
| 5384 | + data: { | |
| 5385 | + action: 'frm_add_form_action', | |
| 5386 | + type: type, | |
| 5387 | + list_id: actionId, | |
| 5388 | + form_id: formId, | |
| 5389 | + nonce: frmGlobal.nonce | |
| 5390 | + }, | |
| 5391 | + success: function( html ) { | |
| 5392 | + fieldUpdated(); | |
| 5393 | + placeholderSetting.remove(); | |
| 5394 | + | |
| 5395 | + // Close any open actions first. | |
| 5396 | + jQuery( '.frm_form_action_settings.open' ).removeClass( 'open' ); | |
| 5397 | + | |
| 5398 | + jQuery( actionsList ).append( html ); | |
| 5399 | + jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' ); | |
| 5400 | + | |
| 5401 | + var newAction = document.getElementById( 'frm_form_action_' + actionId ); | |
| 5402 | + | |
| 5403 | + newAction.classList.add( 'open' ); | |
| 5404 | + document.getElementById( 'post-body-content' ).scroll({ | |
| 5405 | + top: newAction.offsetTop + 10, | |
| 5406 | + left: 0, | |
| 5407 | + behavior: 'smooth' | |
| 5408 | + }); | |
| 5409 | + | |
| 5410 | + //check if icon should be active | |
| 5411 | + checkActiveAction( type ); | |
| 5412 | + initiateMultiselect(); | |
| 5413 | + showInputIcon( '#frm_form_action_' + actionId ); | |
| 5414 | + } | |
| 5415 | + }); | |
| 5416 | + } | |
| 5417 | + | |
| 5418 | + function toggleActionGroups() { | |
| 5419 | + /*jshint validthis:true */ | |
| 5420 | + var actions = document.getElementById( 'frm_email_addon_menu' ).classList, | |
| 5421 | + search = document.getElementById( 'actions-search-input' ); | |
| 5422 | + | |
| 5423 | + if ( actions.contains( 'frm-all-actions' ) ) { | |
| 5424 | + actions.remove( 'frm-all-actions' ); | |
| 5425 | + actions.add( 'frm-limited-actions' ); | |
| 5426 | + } else { | |
| 5427 | + actions.add( 'frm-all-actions' ); | |
| 5428 | + actions.remove( 'frm-limited-actions' ); | |
| 5429 | + } | |
| 5430 | + | |
| 5431 | + // Reset search. | |
| 5432 | + search.value = ''; | |
| 5433 | + triggerEvent( search, 'input' ); | |
| 5434 | + } | |
| 5435 | + | |
| 5436 | + function getNewActionId() { | |
| 5437 | + var actionSettings = document.querySelectorAll( '.frm_form_action_settings' ), | |
| 5438 | + len = getNewRowId( actionSettings, 'frm_form_action_' ); | |
| 5439 | + if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) { | |
| 5440 | + len = len + 100; | |
| 5441 | + } | |
| 5442 | + if ( lastNewActionIdReturned >= len ) { | |
| 5443 | + len = lastNewActionIdReturned + 1; | |
| 5444 | + } | |
| 5445 | + lastNewActionIdReturned = len; | |
| 5446 | + return len; | |
| 5447 | + } | |
| 5448 | + | |
| 5449 | + function clickAction( obj ) { | |
| 5450 | + var $thisobj = jQuery( obj ); | |
| 5451 | + | |
| 5452 | + if ( obj.className.indexOf( 'selected' ) !== -1 ) { | |
| 5453 | + return; | |
| 5454 | + } | |
| 5455 | + if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) { | |
| 5456 | + return; | |
| 5457 | + } | |
| 5458 | + | |
| 5459 | + deselectFields(); | |
| 5460 | + $thisobj.addClass( 'selected' ); | |
| 5461 | + showFieldOptions( obj ); | |
| 5462 | + } | |
| 5463 | + | |
| 5464 | + /** | |
| 5465 | + * When a field is selected, show the field settings in the sidebar. | |
| 5466 | + */ | |
| 5467 | + function showFieldOptions( obj ) { | |
| 5468 | + var i, singleField, | |
| 5469 | + fieldId = obj.getAttribute( 'data-fid' ), | |
| 5470 | + fieldType = obj.getAttribute( 'data-type' ), | |
| 5471 | + allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' ); | |
| 5472 | + | |
| 5473 | + for ( i = 0; i < allFieldSettings.length; i++ ) { | |
| 5474 | + allFieldSettings[i].classList.add( 'frm_hidden' ); | |
| 5475 | + } | |
| 5476 | + | |
| 5477 | + singleField = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 5478 | + moveFieldSettings( singleField ); | |
| 5479 | + | |
| 5480 | + if ( fieldType && 'quantity' === fieldType ) { | |
| 5481 | + popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]); | |
| 5482 | + } | |
| 5483 | + | |
| 5484 | + singleField.classList.remove( 'frm_hidden' ); | |
| 5485 | + document.getElementById( 'frm-options-panel-tab' ).click(); | |
| 5486 | + } | |
| 5487 | + | |
| 5488 | + /** | |
| 5489 | + * Move the settings to the sidebar the first time they are changed or selected. | |
| 5490 | + * Keep the end marker at the end of the form. | |
| 5491 | + */ | |
| 5492 | + function moveFieldSettings( singleField ) { | |
| 5493 | + if ( singleField === null ) { | |
| 5494 | + // The field may have not been loaded yet via ajax. | |
| 5495 | + return; | |
| 5496 | + } | |
| 5497 | + | |
| 5498 | + var classes = singleField.parentElement.classList; | |
| 5499 | + if ( classes.contains( 'frm_field_box' ) || classes.contains( 'divider_section_only' ) ) { | |
| 5500 | + var endMarker = document.getElementById( 'frm-end-form-marker' ); | |
| 5501 | + builderForm.insertBefore( singleField, endMarker ); | |
| 5502 | + } | |
| 5503 | + } | |
| 5504 | + | |
| 5505 | + function showEmailRow() { | |
| 5506 | + /*jshint validthis:true */ | |
| 5507 | + var actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ); | |
| 5508 | + var rowType = this.getAttribute( 'data-emailrow' ); | |
| 5509 | + | |
| 5510 | + jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' ); | |
| 5511 | + jQuery( this ).fadeOut( 'slow' ); | |
| 5512 | + } | |
| 5513 | + | |
| 5514 | + function hideEmailRow() { | |
| 5515 | + /*jshint validthis:true */ | |
| 5516 | + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ), | |
| 5517 | + rowType = this.getAttribute( 'data-emailrow' ), | |
| 5518 | + emailRowSelector = '.frm_' + rowType + '_row', | |
| 5519 | + emailButtonSelector = '.frm_' + rowType + '_button'; | |
| 5520 | + | |
| 5521 | + jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' ); | |
| 5522 | + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() { | |
| 5523 | + jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' ); | |
| 5524 | + }); | |
| 5525 | + } | |
| 5526 | + | |
| 5527 | + function showEmailWarning() { | |
| 5528 | + /*jshint validthis:true */ | |
| 5529 | + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ), | |
| 5530 | + emailRowSelector = '.frm_from_to_match_row', | |
| 5531 | + fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(), | |
| 5532 | + toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val(); | |
| 5533 | + | |
| 5534 | + if ( fromVal === toVal ) { | |
| 5535 | + jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' ); | |
| 5536 | + } else { | |
| 5537 | + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' ); | |
| 5538 | + } | |
| 5539 | + } | |
| 5540 | + | |
| 5541 | + function checkActiveAction( type ) { | |
| 5542 | + var $actionTriggers, limitClass; | |
| 5543 | + | |
| 5544 | + $actionTriggers = jQuery( '.frm_' + type + '_action' ); | |
| 5545 | + | |
| 5546 | + if ( isAtLimitForActionType( type ) ) { | |
| 5547 | + limitClass = 'frm_inactive_action'; | |
| 5548 | + if ( getLimitForActionType( type ) > 0 ) { | |
| 5549 | + limitClass += ' frm_already_used'; | |
| 5550 | + } | |
| 5551 | + $actionTriggers.removeClass( 'frm_active_action' ).addClass( limitClass ); | |
| 5552 | + } else { | |
| 5553 | + $actionTriggers.removeClass( 'frm_inactive_action frm_already_used' ).addClass( 'frm_active_action' ); | |
| 5554 | + } | |
| 5555 | + } | |
| 5556 | + | |
| 5557 | + function isAtLimitForActionType( type ) { | |
| 5558 | + return getNumberOfActionsForType( type ) >= getLimitForActionType( type ); | |
| 5559 | + } | |
| 5560 | + | |
| 5561 | + function getLimitForActionType( type ) { | |
| 5562 | + return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 ); | |
| 5563 | + } | |
| 5564 | + | |
| 5565 | + function getNumberOfActionsForType( type ) { | |
| 5566 | + return jQuery( '.frm_single_' + type + '_settings' ).length; | |
| 5567 | + } | |
| 5568 | + | |
| 5569 | + function onlyOneActionMessage() { | |
| 5570 | + infoModal( frm_admin_js.only_one_action ); | |
| 5571 | + } | |
| 5572 | + | |
| 5573 | + function addFormLogicRow() { | |
| 5574 | + /*jshint validthis:true */ | |
| 5575 | + var id = jQuery( this ).data( 'emailkey' ), | |
| 5576 | + type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(), | |
| 5577 | + formId = document.getElementById( 'form_id' ).value, | |
| 5578 | + logicRows = document.getElementById( 'frm_form_action_' + id ).querySelectorAll( '.frm_logic_row' ); | |
| 5579 | + jQuery.ajax({ | |
| 5580 | + type: 'POST', url: ajaxurl, | |
| 5581 | + data: { | |
| 5582 | + action: 'frm_add_form_logic_row', | |
| 5583 | + email_id: id, | |
| 5584 | + form_id: formId, | |
| 5585 | + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ), | |
| 5586 | + type: type, | |
| 5587 | + nonce: frmGlobal.nonce | |
| 5588 | + }, | |
| 5589 | + success: function( html ) { | |
| 5590 | + jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', function() { | |
| 5591 | + var $logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) ); | |
| 5592 | + $logicRow.append( html ); | |
| 5593 | + $logicRow.parent( '.frm_logic_rows' ).fadeIn( 'slow' ); | |
| 5594 | + }); | |
| 5595 | + } | |
| 5596 | + }); | |
| 5597 | + return false; | |
| 5598 | + } | |
| 5599 | + | |
| 5600 | + function toggleSubmitLogic() { | |
| 5601 | + /*jshint validthis:true */ | |
| 5602 | + if ( this.checked ) { | |
| 5603 | + addSubmitLogic(); | |
| 5604 | + } else { | |
| 5605 | + jQuery( '.frm_logic_row_submit' ).remove(); | |
| 5606 | + document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none'; | |
| 5607 | + } | |
| 5608 | + } | |
| 5609 | + | |
| 5610 | + /** | |
| 5611 | + * Adds submit button Conditional Logic row and reveals submit button Conditional Logic | |
| 5612 | + * | |
| 5613 | + * @returns {boolean} | |
| 5614 | + */ | |
| 5615 | + function addSubmitLogic() { | |
| 5616 | + /*jshint validthis:true */ | |
| 5617 | + var formId = thisFormId, | |
| 5618 | + logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' ); | |
| 5619 | + jQuery.ajax({ | |
| 5620 | + type: 'POST', | |
| 5621 | + url: ajaxurl, | |
| 5622 | + data: { | |
| 5623 | + action: 'frm_add_submit_logic_row', | |
| 5624 | + form_id: formId, | |
| 5625 | + meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ), | |
| 5626 | + nonce: frmGlobal.nonce | |
| 5627 | + }, | |
| 5628 | + success: function( html ) { | |
| 5629 | + var $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) ); | |
| 5630 | + $logicRow.append( html ); | |
| 5631 | + $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' ); | |
| 5632 | + } | |
| 5633 | + }); | |
| 5634 | + return false; | |
| 5635 | + } | |
| 5636 | + | |
| 5637 | + /** | |
| 5638 | + * When the user selects a field for a submit condition, update corresponding options field accordingly. | |
| 5639 | + */ | |
| 5640 | + function addSubmitLogicOpts() { | |
| 5641 | + var fieldOpt = jQuery( this ); | |
| 5642 | + var fieldId = fieldOpt.find( ':selected' ).val(); | |
| 5643 | + | |
| 5644 | + if ( fieldId ) { | |
| 5645 | + var row = fieldOpt.data( 'row' ); | |
| 5646 | + frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' ); | |
| 5647 | + } | |
| 5648 | + } | |
| 5649 | + | |
| 5650 | + function formatEmailSetting() { | |
| 5651 | + /*jshint validthis:true */ | |
| 5652 | + /*var val = jQuery( this ).val(); | |
| 5653 | + var email = val.match( /(\s[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi ); | |
| 5654 | + if(email !== null && email.length) { | |
| 5655 | + //has email | |
| 5656 | + //TODO: add < > if they aren't there | |
| 5657 | + }*/ | |
| 5658 | + } | |
| 5659 | + | |
| 5660 | + function maybeShowFormMessages() { | |
| 5661 | + var header = document.getElementById( 'frm_messages_header' ); | |
| 5662 | + if ( showFormMessages() ) { | |
| 5663 | + header.style.display = 'block'; | |
| 5664 | + } else { | |
| 5665 | + header.style.display = 'none'; | |
| 5666 | + } | |
| 5667 | + } | |
| 5668 | + | |
| 5669 | + function showFormMessages() { | |
| 5670 | + var action = document.getElementById( 'success_action' ); | |
| 5671 | + var selectedAction = action.options[action.selectedIndex].value; | |
| 5672 | + if ( selectedAction === 'message' ) { | |
| 5673 | + return true; | |
| 5674 | + } | |
| 5675 | + | |
| 5676 | + var show = false; | |
| 5677 | + var editable = document.getElementById( 'editable' ); | |
| 5678 | + if ( editable !== null ) { | |
| 5679 | + show = editable.checked && jQuery( document.getElementById( 'edit_action' ) ).val() === 'message'; | |
| 5680 | + if ( ! show ) { | |
| 5681 | + show = isChecked( 'save_draft' ); | |
| 5682 | + } | |
| 5683 | + } | |
| 5684 | + return show; | |
| 5685 | + } | |
| 5686 | + | |
| 5687 | + function checkDupPost() { | |
| 5688 | + /*jshint validthis:true */ | |
| 5689 | + var postField = jQuery( 'select.frm_single_post_field' ); | |
| 5690 | + postField.css( 'border-color', '' ); | |
| 5691 | + var $t = this; | |
| 5692 | + var v = jQuery( $t ).val(); | |
| 5693 | + if ( v === '' || v === 'checkbox' ) { | |
| 5694 | + return false; | |
| 5695 | + } | |
| 5696 | + postField.each( function() { | |
| 5697 | + if ( jQuery( this ).val() === v && this.name !== $t.name ) { | |
| 5698 | + this.style.borderColor = 'red'; | |
| 5699 | + jQuery( $t ).val( '' ); | |
| 5700 | + infoModal( 'Oops. You have already used that field.' ); | |
| 5701 | + return false; | |
| 5702 | + } | |
| 5703 | + }); | |
| 5704 | + } | |
| 5705 | + | |
| 5706 | + function togglePostContent() { | |
| 5707 | + /*jshint validthis:true */ | |
| 5708 | + var v = jQuery( this ).val(); | |
| 5709 | + if ( '' === v ) { | |
| 5710 | + jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' ); | |
| 5711 | + jQuery( '.frm_dyncontent_opt' ).hide(); | |
| 5712 | + } else if ( 'post_content' === v ) { | |
| 5713 | + jQuery( '.frm_post_content_opt' ).show(); | |
| 5714 | + jQuery( '.frm_dyncontent_opt' ).hide(); | |
| 5715 | + jQuery( 'select.frm_dyncontent_opt' ).val( '' ); | |
| 5716 | + } else { | |
| 5717 | + jQuery( '.frm_post_content_opt' ).hide().val( '' ); | |
| 5718 | + jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show(); | |
| 5719 | + } | |
| 5720 | + } | |
| 5721 | + | |
| 5722 | + function fillDyncontent() { | |
| 5723 | + /*jshint validthis:true */ | |
| 5724 | + var v = jQuery( this ).val(); | |
| 5725 | + var $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) ); | |
| 5726 | + if ( '' === v || 'new' === v ) { | |
| 5727 | + $dyn.val( '' ); | |
| 5728 | + jQuery( '.frm_dyncontent_opt' ).show(); | |
| 5729 | + } else { | |
| 5730 | + jQuery.ajax({ | |
| 5731 | + type: 'POST', url: ajaxurl, | |
| 5732 | + data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce}, | |
| 5733 | + success: function( val ) { | |
| 5734 | + $dyn.val( val ); | |
| 5735 | + jQuery( '.frm_dyncontent_opt' ).show(); | |
| 5736 | + } | |
| 5737 | + }); | |
| 5738 | + } | |
| 5739 | + } | |
| 5740 | + | |
| 5741 | + function switchPostType() { | |
| 5742 | + /*jshint validthis:true */ | |
| 5743 | + // update all rows of categories/taxonomies | |
| 5744 | + var curSelect, newSelect, | |
| 5745 | + catRows = document.getElementById( 'frm_posttax_rows' ).childNodes, | |
| 5746 | + postParentField = document.querySelector( '.frm_post_parent_field' ), | |
| 5747 | + postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ), | |
| 5748 | + postType = this.value; | |
| 5749 | + | |
| 5750 | + // Get new category/taxonomy options | |
| 5751 | + jQuery.ajax({ | |
| 5752 | + type: 'POST', | |
| 5753 | + url: ajaxurl, | |
| 5754 | + data: { | |
| 5755 | + action: 'frm_replace_posttax_options', | |
| 5756 | + post_type: postType, | |
| 5757 | + nonce: frmGlobal.nonce | |
| 5758 | + }, | |
| 5759 | + success: function( html ) { | |
| 5760 | + | |
| 5761 | + // Loop through each category row, and replace the first dropdown | |
| 5762 | + for ( i = 0; i < catRows.length; i++ ) { | |
| 5763 | + // Check if current element is a div | |
| 5764 | + if ( catRows[i].tagName !== 'DIV' ) { | |
| 5765 | + continue; | |
| 5766 | + } | |
| 5767 | + | |
| 5768 | + // Get current category select | |
| 5769 | + curSelect = catRows[i].getElementsByTagName( 'select' )[0]; | |
| 5770 | + | |
| 5771 | + // Set up new select | |
| 5772 | + newSelect = document.createElement( 'select' ); | |
| 5773 | + newSelect.innerHTML = html; | |
| 5774 | + newSelect.className = curSelect.className; | |
| 5775 | + newSelect.name = curSelect.name; | |
| 5776 | + | |
| 5777 | + // Replace the old select with the new select | |
| 5778 | + catRows[i].replaceChild( newSelect, curSelect ); | |
| 5779 | + } | |
| 5780 | + } | |
| 5781 | + }); | |
| 5782 | + | |
| 5783 | + // Get new post parent option. | |
| 5784 | + if ( postParentField ) { | |
| 5785 | + getActionOption( | |
| 5786 | + postParentField, | |
| 5787 | + postType, | |
| 5788 | + 'frm_get_post_parent_option', | |
| 5789 | + function( response, optName ) { | |
| 5790 | + // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version. | |
| 5791 | + postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName ); | |
| 5792 | + initAutocomplete( 'page', postParentField ); | |
| 5793 | + } | |
| 5794 | + ); | |
| 5795 | + } | |
| 5796 | + | |
| 5797 | + if ( postMenuOrderField ) { | |
| 5798 | + getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' ); | |
| 5799 | + } | |
| 5800 | + } | |
| 5801 | + | |
| 5802 | + function getActionOption( field, postType, action, successHandler ) { | |
| 5803 | + const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ), | |
| 5804 | + optName = opt.getAttribute( 'name' ); | |
| 5805 | + | |
| 5806 | + jQuery.ajax({ | |
| 5807 | + url: ajaxurl, | |
| 5808 | + method: 'POST', | |
| 5809 | + data: { | |
| 5810 | + action: action, | |
| 5811 | + post_type: postType, | |
| 5812 | + _wpnonce: frmGlobal.nonce | |
| 5813 | + }, | |
| 5814 | + success: response => { | |
| 5815 | + if ( 'string' !== typeof response ) { | |
| 5816 | + console.error( response ); | |
| 5817 | + return; | |
| 5818 | + } | |
| 5819 | + | |
| 5820 | + if ( '0' === response ) { | |
| 5821 | + // This post type does not support this field. | |
| 5822 | + field.classList.add( 'frm_hidden' ); | |
| 5823 | + field.value = ''; | |
| 5824 | + return; | |
| 5825 | + } | |
| 5826 | + | |
| 5827 | + field.classList.remove( 'frm_hidden' ); | |
| 5828 | + | |
| 5829 | + if ( 'function' === typeof successHandler ) { | |
| 5830 | + successHandler( response, optName ); | |
| 5831 | + } | |
| 5832 | + }, | |
| 5833 | + error: response => console.error( response ) | |
| 5834 | + }); | |
| 5835 | + } | |
| 5836 | + | |
| 5837 | + function addPosttaxRow() { | |
| 5838 | + /*jshint validthis:true */ | |
| 5839 | + addPostRow( 'tax', this ); | |
| 5840 | + } | |
| 5841 | + | |
| 5842 | + function addPostmetaRow() { | |
| 5843 | + /*jshint validthis:true */ | |
| 5844 | + addPostRow( 'meta', this ); | |
| 5845 | + } | |
| 5846 | + | |
| 5847 | + function addPostRow( type, button ) { | |
| 5848 | + var name, | |
| 5849 | + id = jQuery( 'input[name="id"]' ).val(), | |
| 5850 | + settings = jQuery( button ).closest( '.frm_form_action_settings' ), | |
| 5851 | + key = settings.data( 'actionkey' ), | |
| 5852 | + postType = settings.find( '.frm_post_type' ).val(), | |
| 5853 | + metaName = 0, | |
| 5854 | + postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' ); | |
| 5855 | + | |
| 5856 | + if ( postTypeRows.length ) { | |
| 5857 | + name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' ); | |
| 5858 | + if ( isNumeric( name ) ) { | |
| 5859 | + metaName = 1 + parseInt( name, 10 ); | |
| 5860 | + } else { | |
| 5861 | + metaName = 1; | |
| 5862 | + } | |
| 5863 | + } | |
| 5864 | + | |
| 5865 | + jQuery.ajax({ | |
| 5866 | + type: 'POST', url: ajaxurl, | |
| 5867 | + data: { | |
| 5868 | + action: 'frm_add_post' + type + '_row', | |
| 5869 | + form_id: id, | |
| 5870 | + meta_name: metaName, | |
| 5871 | + tax_key: metaName, | |
| 5872 | + post_type: postType, | |
| 5873 | + action_key: key, | |
| 5874 | + nonce: frmGlobal.nonce | |
| 5875 | + }, | |
| 5876 | + success: function( html ) { | |
| 5877 | + var cfOpts, optIndex; | |
| 5878 | + jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html ); | |
| 5879 | + jQuery( '.frm_add_post' + type + '_row.button' ).hide(); | |
| 5880 | + | |
| 5881 | + if ( type === 'meta' ) { | |
| 5882 | + jQuery( '.frm_name_value' ).show(); | |
| 5883 | + cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' ); | |
| 5884 | + for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) { | |
| 5885 | + cfOpts[ optIndex ].style.display = 'none'; | |
| 5886 | + } | |
| 5887 | + } else if ( type === 'tax' ) { | |
| 5888 | + jQuery( '.frm_posttax_labels' ).show(); | |
| 5889 | + } | |
| 5890 | + } | |
| 5891 | + }); | |
| 5892 | + } | |
| 5893 | + | |
| 5894 | + function isNumeric( value ) { | |
| 5895 | + return ! isNaN( parseFloat( value ) ) && isFinite( value ); | |
| 5896 | + } | |
| 5897 | + | |
| 5898 | + function getMetaValue( id, metaName ) { | |
| 5899 | + var newMeta = metaName; | |
| 5900 | + if ( jQuery( document.getElementById( id + metaName ) ).length > 0 ) { | |
| 5901 | + newMeta = getMetaValue( id, metaName + 1 ); | |
| 5902 | + } | |
| 5903 | + return newMeta; | |
| 5904 | + } | |
| 5905 | + | |
| 5906 | + function changePosttaxRow() { | |
| 5907 | + /*jshint validthis:true */ | |
| 5908 | + if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) { | |
| 5909 | + return; | |
| 5910 | + } | |
| 5911 | + | |
| 5912 | + jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' ); | |
| 5913 | + | |
| 5914 | + var postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(), | |
| 5915 | + actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ), | |
| 5916 | + taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ), | |
| 5917 | + metaName = jQuery( this ).val(), | |
| 5918 | + showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0, | |
| 5919 | + fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(), | |
| 5920 | + id = jQuery( 'input[name="id"]' ).val(); | |
| 5921 | + | |
| 5922 | + jQuery.ajax({ | |
| 5923 | + type: 'POST', | |
| 5924 | + url: ajaxurl, | |
| 5925 | + data: { | |
| 5926 | + action: 'frm_add_posttax_row', | |
| 5927 | + form_id: id, | |
| 5928 | + post_type: postType, | |
| 5929 | + tax_key: taxKey, | |
| 5930 | + action_key: actionKey, | |
| 5931 | + meta_name: metaName, | |
| 5932 | + field_id: fieldId, | |
| 5933 | + show_exclude: showExclude, | |
| 5934 | + nonce: frmGlobal.nonce | |
| 5935 | + }, | |
| 5936 | + success: function( html ) { | |
| 5937 | + var $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) ); | |
| 5938 | + $tax.replaceWith( html ); | |
| 5939 | + } | |
| 5940 | + }); | |
| 5941 | + } | |
| 5942 | + | |
| 5943 | + function toggleCfOpts() { | |
| 5944 | + /*jshint validthis:true */ | |
| 5945 | + var row = jQuery( this ).closest( '.frm_postmeta_row' ); | |
| 5946 | + var cancel = row.find( '.frm_cancelnew' ); | |
| 5947 | + var select = row.find( '.frm_enternew' ); | |
| 5948 | + if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) { | |
| 5949 | + cancel.hide(); | |
| 5950 | + select.show(); | |
| 5951 | + } else { | |
| 5952 | + cancel.show(); | |
| 5953 | + select.hide(); | |
| 5954 | + } | |
| 5955 | + | |
| 5956 | + row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' ); | |
| 5957 | + return false; | |
| 5958 | + } | |
| 5959 | + | |
| 5960 | + function toggleFormOpts() { | |
| 5961 | + /*jshint validthis:true */ | |
| 5962 | + var changedOpt = jQuery( this ); | |
| 5963 | + var val = changedOpt.val(); | |
| 5964 | + if ( changedOpt.attr( 'type' ) === 'checkbox' ) { | |
| 5965 | + if ( this.checked === false ) { | |
| 5966 | + val = ''; | |
| 5967 | + } | |
| 5968 | + } | |
| 5969 | + | |
| 5970 | + var toggleClass = changedOpt.data( 'toggleclass' ); | |
| 5971 | + if ( val === '' ) { | |
| 5972 | + jQuery( '.' + toggleClass ).hide(); | |
| 5973 | + } else { | |
| 5974 | + jQuery( '.' + toggleClass ).show(); | |
| 5975 | + jQuery( '.hide_' + toggleClass + '_' + val ).hide(); | |
| 5976 | + } | |
| 5977 | + } | |
| 5978 | + | |
| 5979 | + function submitSettings() { | |
| 5980 | + /*jshint validthis:true */ | |
| 5981 | + preFormSave( this ); | |
| 5982 | + triggerSubmit( document.querySelector( '.frm_form_settings' ) ); | |
| 5983 | + } | |
| 5984 | + | |
| 5985 | + /* View Functions */ | |
| 5986 | + function showCount() { | |
| 5987 | + /*jshint validthis:true */ | |
| 5988 | + var value = jQuery( this ).val(); | |
| 5989 | + | |
| 5990 | + var $cont = document.getElementById( 'date_select_container' ); | |
| 5991 | + var tab = document.getElementById( 'frm_listing_tab' ); | |
| 5992 | + var label = tab.getAttribute( 'data-label' ); | |
| 5993 | + if ( value === 'calendar' ) { | |
| 5994 | + jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 5995 | + jQuery( '.limit_container' ).addClass( 'frm_hidden' ); | |
| 5996 | + $cont.style.display = 'block'; | |
| 5997 | + } else if ( value === 'dynamic' ) { | |
| 5998 | + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 5999 | + } else if ( value === 'one' ) { | |
| 6000 | + label = tab.getAttribute( 'data-one' ); | |
| 6001 | + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' ); | |
| 6002 | + } else { | |
| 6003 | + jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' ); | |
| 6004 | + jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 6005 | + } | |
| 6006 | + | |
| 6007 | + if ( value !== 'calendar' ) { | |
| 6008 | + $cont.style.display = 'none'; | |
| 6009 | + } | |
| 6010 | + tab.innerHTML = label; | |
| 6011 | + } | |
| 6012 | + | |
| 6013 | + function displayFormSelected() { | |
| 6014 | + /*jshint validthis:true */ | |
| 6015 | + var formId = jQuery( this ).val(); | |
| 6016 | + thisFormId = formId; // set the global form id | |
| 6017 | + if ( formId === '' ) { | |
| 6018 | + return; | |
| 6019 | + } | |
| 6020 | + | |
| 6021 | + jQuery.ajax({ | |
| 6022 | + type: 'POST', | |
| 6023 | + url: ajaxurl, | |
| 6024 | + data: { | |
| 6025 | + action: 'frm_get_cd_tags_box', | |
| 6026 | + form_id: formId, | |
| 6027 | + nonce: frmGlobal.nonce | |
| 6028 | + }, | |
| 6029 | + success: function( html ) { | |
| 6030 | + jQuery( '#frm_adv_info .categorydiv' ).html( html ); | |
| 6031 | + } | |
| 6032 | + }); | |
| 6033 | + | |
| 6034 | + jQuery.ajax({ | |
| 6035 | + type: 'POST', | |
| 6036 | + url: ajaxurl, | |
| 6037 | + data: { | |
| 6038 | + action: 'frm_get_date_field_select', | |
| 6039 | + form_id: formId, | |
| 6040 | + nonce: frmGlobal.nonce | |
| 6041 | + }, | |
| 6042 | + success: function( html ) { | |
| 6043 | + jQuery( document.getElementById( 'date_select_container' ) ).html( html ); | |
| 6044 | + } | |
| 6045 | + }); | |
| 6046 | + } | |
| 6047 | + | |
| 6048 | + function clickTabsAfterAjax() { | |
| 6049 | + /*jshint validthis:true */ | |
| 6050 | + var t = jQuery( this ).attr( 'href' ); | |
| 6051 | + jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' ); | |
| 6052 | + jQuery( t ).show().siblings( '.tabs-panel' ).hide(); | |
| 6053 | + return false; | |
| 6054 | + } | |
| 6055 | + | |
| 6056 | + function clickContentTab() { | |
| 6057 | + /*jshint validthis:true */ | |
| 6058 | + link = jQuery( this ); | |
| 6059 | + var t = link.attr( 'href' ); | |
| 6060 | + if ( typeof t === 'undefined' ) { | |
| 6061 | + return false; | |
| 6062 | + } | |
| 6063 | + | |
| 6064 | + var c = t.replace( '#', '.' ); | |
| 6065 | + link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' ); | |
| 6066 | + link.addClass( 'nav-tab-active' ); | |
| 6067 | + jQuery( '.nav-menu-content' ).not( t ).not( c ).hide(); | |
| 6068 | + jQuery( t + ',' + c ).show(); | |
| 6069 | + | |
| 6070 | + return false; | |
| 6071 | + } | |
| 6072 | + | |
| 6073 | + function addOrderRow() { | |
| 6074 | + var logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' ); | |
| 6075 | + jQuery.ajax({ | |
| 6076 | + type: 'POST', | |
| 6077 | + url: ajaxurl, | |
| 6078 | + data: { | |
| 6079 | + action: 'frm_add_order_row', | |
| 6080 | + form_id: thisFormId, | |
| 6081 | + order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ), | |
| 6082 | + nonce: frmGlobal.nonce | |
| 6083 | + }, | |
| 6084 | + success: function( html ) { | |
| 6085 | + jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide(); | |
| 6086 | + } | |
| 6087 | + }); | |
| 6088 | + } | |
| 6089 | + | |
| 6090 | + function addWhereRow() { | |
| 6091 | + var rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' ); | |
| 6092 | + jQuery.ajax({ | |
| 6093 | + type: 'POST', | |
| 6094 | + url: ajaxurl, | |
| 6095 | + data: { | |
| 6096 | + action: 'frm_add_where_row', | |
| 6097 | + form_id: thisFormId, | |
| 6098 | + where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ), | |
| 6099 | + nonce: frmGlobal.nonce | |
| 6100 | + }, | |
| 6101 | + success: function( html ) { | |
| 6102 | + jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide(); | |
| 6103 | + } | |
| 6104 | + }); | |
| 6105 | + } | |
| 6106 | + | |
| 6107 | + function insertWhereOptions() { | |
| 6108 | + /*jshint validthis:true */ | |
| 6109 | + var value = this.value, | |
| 6110 | + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); | |
| 6111 | + | |
| 6112 | + jQuery.ajax({ | |
| 6113 | + type: 'POST', | |
| 6114 | + url: ajaxurl, | |
| 6115 | + data: { | |
| 6116 | + action: 'frm_add_where_options', | |
| 6117 | + where_key: whereKey, | |
| 6118 | + field_id: value, | |
| 6119 | + nonce: frmGlobal.nonce | |
| 6120 | + }, | |
| 6121 | + success: function( html ) { | |
| 6122 | + jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html ); | |
| 6123 | + } | |
| 6124 | + }); | |
| 6125 | + } | |
| 6126 | + | |
| 6127 | + function hideWhereOptions() { | |
| 6128 | + /*jshint validthis:true */ | |
| 6129 | + var value = this.value, | |
| 6130 | + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); | |
| 6131 | + | |
| 6132 | + if ( value === 'group_by' || value === 'group_by_newest' ) { | |
| 6133 | + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none'; | |
| 6134 | + } else { | |
| 6135 | + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block'; | |
| 6136 | + } | |
| 6137 | + } | |
| 6138 | + | |
| 6139 | + function setDefaultPostStatus() { | |
| 6140 | + var urlQuery = window.location.search.substring( 1 ); | |
| 6141 | + if ( urlQuery.indexOf( 'action=edit' ) === -1 ) { | |
| 6142 | + document.getElementById( 'post-visibility-display' ).innerHTML = frm_admin_js.private_label; | |
| 6143 | + document.getElementById( 'hidden-post-visibility' ).value = 'private'; | |
| 6144 | + document.getElementById( 'visibility-radio-private' ).checked = true; | |
| 6145 | + } | |
| 6146 | + } | |
| 6147 | + | |
| 6148 | + /* Customization Panel */ | |
| 6149 | + function insertCode( e ) { | |
| 6150 | + /*jshint validthis:true */ | |
| 6151 | + e.preventDefault(); | |
| 6152 | + insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) ); | |
| 6153 | + return false; | |
| 6154 | + } | |
| 6155 | + | |
| 6156 | + function insertFieldCode( element, variable ) { | |
| 6157 | + var rich = false, | |
| 6158 | + elementId = element; | |
| 6159 | + if ( typeof element === 'object' ) { | |
| 6160 | + if ( element.hasClass( 'frm_noallow' ) ) { | |
| 6161 | + return; | |
| 6162 | + } | |
| 6163 | + | |
| 6164 | + elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' ); | |
| 6165 | + if ( typeof elementId === 'undefined' ) { | |
| 6166 | + elementId = element.closest( 'div' ).attr( 'class' ); | |
| 6167 | + if ( typeof elementId !== 'undefined' ) { | |
| 6168 | + elementId = elementId.split( ' ' )[1]; | |
| 6169 | + } | |
| 6170 | + } | |
| 6171 | + } | |
| 6172 | + | |
| 6173 | + if ( typeof elementId === 'undefined' ) { | |
| 6174 | + var active = document.activeElement; | |
| 6175 | + if ( active.type === 'search' ) { | |
| 6176 | + // If the search field has focus, find the correct field. | |
| 6177 | + elementId = active.id.replace( '-search-input', '' ); | |
| 6178 | + if ( elementId.match( /\d/gi ) === null ) { | |
| 6179 | + active = jQuery( '.frm-single-settings:visible .' + elementId ); | |
| 6180 | + elementId = active.attr( 'id' ); | |
| 6181 | + } | |
| 6182 | + } else { | |
| 6183 | + elementId = active.id; | |
| 6184 | + } | |
| 6185 | + } | |
| 6186 | + | |
| 6187 | + if ( elementId ) { | |
| 6188 | + rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0; | |
| 6189 | + } | |
| 6190 | + | |
| 6191 | + var contentBox = jQuery( document.getElementById( elementId ) ); | |
| 6192 | + if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) { | |
| 6193 | + // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field | |
| 6194 | + var doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' ); | |
| 6195 | + if ( doShortcode === 'undefined' || doShortcode !== 'no' ) { | |
| 6196 | + variable = '[' + variable + ']'; | |
| 6197 | + } | |
| 6198 | + } | |
| 6199 | + | |
| 6200 | + if ( rich ) { | |
| 6201 | + wpActiveEditor = elementId; | |
| 6202 | + send_to_editor( variable ); | |
| 6203 | + return; | |
| 6204 | + } | |
| 6205 | + | |
| 6206 | + if ( ! contentBox.length ) { | |
| 6207 | + return false; | |
| 6208 | + } | |
| 6209 | + | |
| 6210 | + if ( variable === '[default-html]' || variable === '[default-plain]' ) { | |
| 6211 | + var p = 0; | |
| 6212 | + if ( variable === '[default-plain]' ) { | |
| 6213 | + p = 1; | |
| 6214 | + } | |
| 6215 | + jQuery.ajax({ | |
| 6216 | + type: 'POST', url: ajaxurl, | |
| 6217 | + data: { | |
| 6218 | + action: 'frm_get_default_html', | |
| 6219 | + form_id: jQuery( 'input[name="id"]' ).val(), | |
| 6220 | + plain_text: p, | |
| 6221 | + nonce: frmGlobal.nonce | |
| 6222 | + }, | |
| 6223 | + success: function( msg ) { | |
| 6224 | + insertContent( contentBox, msg ); | |
| 6225 | + } | |
| 6226 | + }); | |
| 6227 | + } else { | |
| 6228 | + insertContent( contentBox, variable ); | |
| 6229 | + } | |
| 6230 | + return false; | |
| 6231 | + } | |
| 6232 | + | |
| 6233 | + function insertContent( contentBox, variable ) { | |
| 6234 | + if ( document.selection ) { | |
| 6235 | + contentBox[0].focus(); | |
| 6236 | + document.selection.createRange().text = variable; | |
| 6237 | + } else { | |
| 6238 | + obj = contentBox[0]; | |
| 6239 | + var e = obj.selectionEnd; | |
| 6240 | + | |
| 6241 | + variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e ); | |
| 6242 | + | |
| 6243 | + obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length ); | |
| 6244 | + var s = e + variable.length; | |
| 6245 | + obj.focus(); | |
| 6246 | + obj.setSelectionRange( s, s ); | |
| 6247 | + } | |
| 6248 | + triggerChange( contentBox ); | |
| 6249 | + } | |
| 6250 | + | |
| 6251 | + function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) { | |
| 6252 | + var separator = input.data( 'sep' ); | |
| 6253 | + if ( undefined === separator ) { | |
| 6254 | + return textToInsert; | |
| 6255 | + } | |
| 6256 | + | |
| 6257 | + var value = input.val(); | |
| 6258 | + | |
| 6259 | + if ( ! value.trim().length ) { | |
| 6260 | + return textToInsert; | |
| 6261 | + } | |
| 6262 | + | |
| 6263 | + var startPattern = new RegExp( separator + '\\s*$' ); | |
| 6264 | + var endPattern = new RegExp( '^\\s*' + separator ); | |
| 6265 | + | |
| 6266 | + if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) { | |
| 6267 | + textToInsert = separator + textToInsert; | |
| 6268 | + } | |
| 6269 | + | |
| 6270 | + if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) { | |
| 6271 | + textToInsert += separator; | |
| 6272 | + } | |
| 6273 | + | |
| 6274 | + return textToInsert; | |
| 6275 | + } | |
| 6276 | + | |
| 6277 | + function resetLogicBuilder() { | |
| 6278 | + /*jshint validthis:true */ | |
| 6279 | + var id = document.getElementById( 'frm-id-condition' ), | |
| 6280 | + key = document.getElementById( 'frm-key-condition' ); | |
| 6281 | + | |
| 6282 | + if ( this.checked ) { | |
| 6283 | + id.classList.remove( 'frm_hidden' ); | |
| 6284 | + key.classList.add( 'frm_hidden' ); | |
| 6285 | + triggerEvent( key, 'change' ); | |
| 6286 | + } else { | |
| 6287 | + id.classList.add( 'frm_hidden' ); | |
| 6288 | + key.classList.remove( 'frm_hidden' ); | |
| 6289 | + triggerEvent( id, 'change' ); | |
| 6290 | + } | |
| 6291 | + } | |
| 6292 | + | |
| 6293 | + function setLogicExample() { | |
| 6294 | + var field, code, | |
| 6295 | + idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition', | |
| 6296 | + is = document.getElementById( 'frm-is-condition' ).value, | |
| 6297 | + text = document.getElementById( 'frm-text-condition' ).value, | |
| 6298 | + result = document.getElementById( 'frm-insert-condition' ); | |
| 6299 | + | |
| 6300 | + idKey = document.getElementById( idKey ); | |
| 6301 | + field = idKey.options[idKey.selectedIndex].value; | |
| 6302 | + code = 'if ' + field + ' ' + is + '="' + text + '"]'; | |
| 6303 | + result.setAttribute( 'data-code', code + frm_admin_js.conditional_text + '[/if ' + field ); | |
| 6304 | + result.innerHTML = '[' + code + '[/if ' + field + ']'; | |
| 6305 | + } | |
| 6306 | + | |
| 6307 | + function showBuilderModal() { | |
| 6308 | + /*jshint validthis:true */ | |
| 6309 | + var moreIcon = getIconForInput( this ); | |
| 6310 | + showInlineModal( moreIcon, this ); | |
| 6311 | + } | |
| 6312 | + | |
| 6313 | + function maybeShowModal( input ) { | |
| 6314 | + var moreIcon; | |
| 6315 | + if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) { | |
| 6316 | + hideShortcodes(); | |
| 6317 | + moreIcon = getIconForInput( input ); | |
| 6318 | + if ( moreIcon.tagName === 'use' ) { | |
| 6319 | + moreIcon = moreIcon.firstElementChild; | |
| 6320 | + if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) { | |
| 6321 | + showShortcodeBox( moreIcon, 'nofocus' ); | |
| 6322 | + } | |
| 6323 | + } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) { | |
| 6324 | + showShortcodeBox( moreIcon, 'nofocus' ); | |
| 6325 | + } | |
| 6326 | + } | |
| 6327 | + } | |
| 6328 | + | |
| 6329 | + function showShortcodes( e ) { | |
| 6330 | + /*jshint validthis:true */ | |
| 6331 | + e.preventDefault(); | |
| 6332 | + e.stopPropagation(); | |
| 6333 | + | |
| 6334 | + showShortcodeBox( this ); | |
| 6335 | + } | |
| 6336 | + | |
| 6337 | + function showShortcodeBox( moreIcon, shouldFocus ) { | |
| 6338 | + var pos = moreIcon.getBoundingClientRect(), | |
| 6339 | + input = getInputForIcon( moreIcon ), | |
| 6340 | + box = document.getElementById( 'frm_adv_info' ), | |
| 6341 | + classes = moreIcon.className, | |
| 6342 | + parentPos = box.parentElement.getBoundingClientRect(); | |
| 6343 | + | |
| 6344 | + if ( moreIcon.tagName === 'svg' ) { | |
| 6345 | + moreIcon = moreIcon.firstElementChild; | |
| 6346 | + } | |
| 6347 | + if ( moreIcon.tagName === 'use' ) { | |
| 6348 | + classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ); | |
| 6349 | + } | |
| 6350 | + | |
| 6351 | + if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) { | |
| 6352 | + hideShortcodes( box ); | |
| 6353 | + } else { | |
| 6354 | + box.style.top = ( pos.top - parentPos.top + 32 ) + 'px'; | |
| 6355 | + box.style.left = ( pos.left - parentPos.left - 257 ) + 'px'; | |
| 6356 | + | |
| 6357 | + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ); | |
| 6358 | + if ( input.classList.contains( 'frm_not_email_to' ) ) { | |
| 6359 | + jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' ); | |
| 6360 | + } else if ( input.classList.contains( 'frm_not_email_subject' ) ) { | |
| 6361 | + jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' ); | |
| 6362 | + } | |
| 6363 | + | |
| 6364 | + box.setAttribute( 'data-fills', input.id ); | |
| 6365 | + box.style.display = 'block'; | |
| 6366 | + | |
| 6367 | + if ( moreIcon.tagName === 'use' ) { | |
| 6368 | + moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' ); | |
| 6369 | + } else { | |
| 6370 | + moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' ); | |
| 6371 | + } | |
| 6372 | + | |
| 6373 | + if ( shouldFocus !== 'nofocus' ) { | |
| 6374 | + input.focus(); | |
| 6375 | + } | |
| 6376 | + } | |
| 6377 | + } | |
| 6378 | + | |
| 6379 | + function fieldUpdated() { | |
| 6380 | + if ( ! fieldsUpdated ) { | |
| 6381 | + fieldsUpdated = 1; | |
| 6382 | + window.addEventListener( 'beforeunload', confirmExit ); | |
| 6383 | + } | |
| 6384 | + } | |
| 6385 | + | |
| 6386 | + function buildSubmittedNoAjax() { | |
| 6387 | + // set fieldsUpdated to 0 to avoid the unsaved changes pop up | |
| 6388 | + fieldsUpdated = 0; | |
| 6389 | + } | |
| 6390 | + | |
| 6391 | + function settingsSubmitted() { | |
| 6392 | + // set fieldsUpdated to 0 to avoid the unsaved changes pop up | |
| 6393 | + fieldsUpdated = 0; | |
| 6394 | + } | |
| 6395 | + | |
| 6396 | + function confirmExit( event ) { | |
| 6397 | + if ( fieldsUpdated ) { | |
| 6398 | + event.preventDefault(); | |
| 6399 | + event.returnValue = ''; | |
| 6400 | + } | |
| 6401 | + } | |
| 6402 | + | |
| 6403 | + function bindClickForDialogClose( $modal ) { | |
| 6404 | + jQuery( '.ui-widget-overlay, a.dismiss' ).on( 'click', function() { | |
| 6405 | + $modal.dialog( 'close' ); | |
| 6406 | + }); | |
| 6407 | + } | |
| 6408 | + | |
| 6409 | + function triggerNewFormModal( event ) { | |
| 6410 | + var $modal, | |
| 6411 | + dismiss = document.getElementById( 'frm_new_form_modal' ).querySelector( 'a.dismiss' ); | |
| 6412 | + | |
| 6413 | + if ( typeof event !== 'undefined' ) { | |
| 6414 | + event.preventDefault(); | |
| 6415 | + } | |
| 6416 | + | |
| 6417 | + dismiss.setAttribute( 'tabindex', -1 ); | |
| 6418 | + | |
| 6419 | + $modal = initModal( '#frm_new_form_modal', '600px' ); | |
| 6420 | + $modal.attr( 'frm-page', 'create' ); | |
| 6421 | + $modal.find( '#template-search-input' ).val( '' ).trigger( 'change' ); | |
| 6422 | + $modal.dialog( 'open' ); | |
| 6423 | + | |
| 6424 | + dismiss.removeAttribute( 'tabindex' ); | |
| 6425 | + bindClickForDialogClose( $modal ); | |
| 6426 | + } | |
| 6427 | + | |
| 6428 | + /** | |
| 6429 | + * Get the input box for the selected ... icon. | |
| 6430 | + */ | |
| 6431 | + function getInputForIcon( moreIcon ) { | |
| 6432 | + var input = moreIcon.nextElementSibling; | |
| 6433 | + if ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) { | |
| 6434 | + // Workaround for 1Password. | |
| 6435 | + input = input.nextElementSibling; | |
| 6436 | + } | |
| 6437 | + return input; | |
| 6438 | + } | |
| 6439 | + | |
| 6440 | + /** | |
| 6441 | + * Get the ... icon for the selected input box. | |
| 6442 | + */ | |
| 6443 | + function getIconForInput( input ) { | |
| 6444 | + var moreIcon = input.previousElementSibling; | |
| 6445 | + if ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) { | |
| 6446 | + moreIcon = moreIcon.previousElementSibling; | |
| 6447 | + } | |
| 6448 | + return moreIcon; | |
| 6449 | + } | |
| 6450 | + | |
| 6451 | + function hideShortcodes( box ) { | |
| 6452 | + var i, u, closeIcons, closeSvg; | |
| 6453 | + if ( typeof box === 'undefined' ) { | |
| 6454 | + box = document.getElementById( 'frm_adv_info' ); | |
| 6455 | + if ( box === null ) { | |
| 6456 | + return; | |
| 6457 | + } | |
| 6458 | + } | |
| 6459 | + | |
| 6460 | + if ( document.getElementById( 'frm_dyncontent' ) !== null ) { | |
| 6461 | + // Don't run when in the sidebar. | |
| 6462 | + return; | |
| 6463 | + } | |
| 6464 | + | |
| 6465 | + box.style.display = 'none'; | |
| 6466 | + | |
| 6467 | + closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' ); | |
| 6468 | + for ( i = 0; i < closeIcons.length; i++ ) { | |
| 6469 | + closeIcons[i].classList.remove( 'frm_close_icon' ); | |
| 6470 | + closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' ); | |
| 6471 | + } | |
| 6472 | + | |
| 6473 | + closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' ); | |
| 6474 | + for ( u = 0; u < closeSvg.length; u++ ) { | |
| 6475 | + if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) { | |
| 6476 | + closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' ); | |
| 6477 | + } | |
| 6478 | + } | |
| 6479 | + } | |
| 6480 | + | |
| 6481 | + function initToggleShortcodes() { | |
| 6482 | + if ( typeof tinymce !== 'object' ) { | |
| 6483 | + return; | |
| 6484 | + } | |
| 6485 | + | |
| 6486 | + DOM = tinymce.DOM; | |
| 6487 | + if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) { | |
| 6488 | + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() { | |
| 6489 | + if ( jQuery( '*:focus' ).length > 0 ) { | |
| 6490 | + return; | |
| 6491 | + } | |
| 6492 | + if ( this.id ) { | |
| 6493 | + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 6494 | + } | |
| 6495 | + }); | |
| 6496 | + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() { | |
| 6497 | + if ( jQuery( '*:focus' ).length > 0 ) { | |
| 6498 | + return; | |
| 6499 | + } | |
| 6500 | + if ( this.id ) { | |
| 6501 | + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 6502 | + } | |
| 6503 | + }); | |
| 6504 | + } else { | |
| 6505 | + jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() { | |
| 6506 | + if ( jQuery( '*:focus' ).length > 0 ) { | |
| 6507 | + return; | |
| 6508 | + } | |
| 6509 | + if ( this.id ) { | |
| 6510 | + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 6511 | + } | |
| 6512 | + }); | |
| 6513 | + } | |
| 6514 | + } | |
| 6515 | + | |
| 6516 | + function toggleAllowedShortcodes( id ) { | |
| 6517 | + var c, clickedID; | |
| 6518 | + if ( typeof id === 'undefined' ) { | |
| 6519 | + id = ''; | |
| 6520 | + } | |
| 6521 | + c = id; | |
| 6522 | + | |
| 6523 | + if ( id.indexOf( '-search-input' ) !== -1 ) { | |
| 6524 | + return; | |
| 6525 | + } | |
| 6526 | + | |
| 6527 | + if ( id !== '' ) { | |
| 6528 | + var $ele = jQuery( document.getElementById( id ) ); | |
| 6529 | + if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) { | |
| 6530 | + var d = $ele.attr( 'class' ).split( ' ' )[0]; | |
| 6531 | + if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) { | |
| 6532 | + d = ''; | |
| 6533 | + } else { | |
| 6534 | + id = d.trim(); | |
| 6535 | + } | |
| 6536 | + c = c + ' ' + d; | |
| 6537 | + c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' ); | |
| 6538 | + } | |
| 6539 | + } | |
| 6540 | + | |
| 6541 | + jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() ); | |
| 6542 | + var a = [ | |
| 6543 | + 'content', 'wpbody-content', 'dyncontent', 'success_url', | |
| 6544 | + 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message', | |
| 6545 | + 'frm_not_email_subject' | |
| 6546 | + ]; | |
| 6547 | + var b = [ | |
| 6548 | + 'before_content', 'after_content', 'frm_not_email_to', | |
| 6549 | + 'dyn_default_value' | |
| 6550 | + ]; | |
| 6551 | + | |
| 6552 | + if ( jQuery.inArray( id, a ) >= 0 ) { | |
| 6553 | + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); | |
| 6554 | + jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 6555 | + } else if ( jQuery.inArray( id, b ) >= 0 ) { | |
| 6556 | + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 6557 | + jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); | |
| 6558 | + } else { | |
| 6559 | + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 6560 | + } | |
| 6561 | + | |
| 6562 | + // Automatically select a tab. | |
| 6563 | + if ( id === 'dyn_default_value' ) { | |
| 6564 | + clickedID = 'frm_dynamic_values'; | |
| 6565 | + document.getElementById( clickedID + '_tab' ).click(); | |
| 6566 | + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' ); | |
| 6567 | + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' ); | |
| 6568 | + } | |
| 6569 | + } | |
| 6570 | + | |
| 6571 | + function toggleAllowedHTML( input ) { | |
| 6572 | + var b, | |
| 6573 | + id = input.id; | |
| 6574 | + if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) { | |
| 6575 | + return; | |
| 6576 | + } | |
| 6577 | + | |
| 6578 | + jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() ); | |
| 6579 | + if ( input.classList.contains( 'field_custom_html' ) ) { | |
| 6580 | + id = 'field_custom_html'; | |
| 6581 | + } | |
| 6582 | + | |
| 6583 | + b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ]; | |
| 6584 | + if ( jQuery.inArray( id, b ) >= 0 ) { | |
| 6585 | + jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' ); | |
| 6586 | + jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' ); | |
| 6587 | + } | |
| 6588 | + } | |
| 6589 | + | |
| 6590 | + function toggleKeyID( switchTo, e ) { | |
| 6591 | + e.stopPropagation(); | |
| 6592 | + jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' ); | |
| 6593 | + jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' ); | |
| 6594 | + jQuery( '.frmids, .frmkeys' ).removeClass( 'current' ); | |
| 6595 | + jQuery( '.' + switchTo ).addClass( 'current' ); | |
| 6596 | + } | |
| 6597 | + | |
| 6598 | + /* Styling */ | |
| 6599 | + | |
| 6600 | + //function to append a new theme stylesheet with the new style changes | |
| 6601 | + function updateUICSS( locStr ) { | |
| 6602 | + var $cssLink, $link; | |
| 6603 | + | |
| 6604 | + if ( locStr == -1 ) { | |
| 6605 | + jQuery( 'link.ui-theme' ).remove(); | |
| 6606 | + return false; | |
| 6607 | + } | |
| 6608 | + | |
| 6609 | + $cssLink = jQuery( '<link href="' + locStr + '" type="text/css" rel="Stylesheet" class="ui-theme" />' ); | |
| 6610 | + jQuery( 'head' ).append( $cssLink ); | |
| 6611 | + | |
| 6612 | + $link = jQuery( 'link.ui-theme' ); | |
| 6613 | + if ( $link.length > 1 ) { | |
| 6614 | + $link.first().remove(); | |
| 6615 | + } | |
| 6616 | + } | |
| 6617 | + | |
| 6618 | + function setPosClass() { | |
| 6619 | + /*jshint validthis:true */ | |
| 6620 | + var value = this.value; | |
| 6621 | + if ( value === 'none' ) { | |
| 6622 | + value = 'top'; | |
| 6623 | + } else if ( value === 'no_label' ) { | |
| 6624 | + value = 'none'; | |
| 6625 | + } | |
| 6626 | + jQuery( '.frm_pos_container' ).removeClass( 'frm_top_container frm_left_container frm_right_container frm_none_container frm_inside_container' ).addClass( 'frm_' + value + '_container' ); | |
| 6627 | + } | |
| 6628 | + | |
| 6629 | + function collapseAllSections() { | |
| 6630 | + jQuery( '.control-section.accordion-section.open' ).removeClass( 'open' ); | |
| 6631 | + } | |
| 6632 | + | |
| 6633 | + function textSquishCheck() { | |
| 6634 | + var size = document.getElementById( 'frm_field_font_size' ).value.replace( /\D/g, '' ); | |
| 6635 | + var height = document.getElementById( 'frm_field_height' ).value.replace( /\D/g, '' ); | |
| 6636 | + var paddingEntered = document.getElementById( 'frm_field_pad' ).value.split( ' ' ); | |
| 6637 | + var paddingCount = paddingEntered.length; | |
| 6638 | + | |
| 6639 | + // If too many or too few padding entries, leave now | |
| 6640 | + if ( paddingCount === 0 || paddingCount > 4 || height === '' ) { | |
| 6641 | + return; | |
| 6642 | + } | |
| 6643 | + | |
| 6644 | + // Get the top and bottom padding from entered values | |
| 6645 | + var paddingTop = paddingEntered[0].replace( /\D/g, '' ); | |
| 6646 | + var paddingBottom = paddingTop; | |
| 6647 | + if ( paddingCount >= 3 ) { | |
| 6648 | + paddingBottom = paddingEntered[2].replace( /\D/g, '' ); | |
| 6649 | + } | |
| 6650 | + | |
| 6651 | + // Check if there is enough space for text | |
| 6652 | + var textSpace = height - size - paddingTop - paddingBottom - 3; | |
| 6653 | + if ( textSpace < 0 ) { | |
| 6654 | + infoModal( frm_admin_js.css_invalid_size ); | |
| 6655 | + } | |
| 6656 | + } | |
| 6657 | + | |
| 6658 | + /* Global settings page */ | |
| 6659 | + function loadSettingsTab( anchor ) { | |
| 6660 | + var holder = anchor.replace( '#', '' ); | |
| 6661 | + var holderContainer = jQuery( '.frm_' + holder + '_ajax' ); | |
| 6662 | + if ( holderContainer.length ) { | |
| 6663 | + jQuery.ajax({ | |
| 6664 | + type: 'POST', url: ajaxurl, | |
| 6665 | + data: { | |
| 6666 | + 'action': 'frm_settings_tab', | |
| 6667 | + 'tab': holder.replace( '_settings', '' ), | |
| 6668 | + 'nonce': frmGlobal.nonce | |
| 6669 | + }, | |
| 6670 | + success: function( html ) { | |
| 6671 | + holderContainer.replaceWith( html ); | |
| 6672 | + } | |
| 6673 | + }); | |
| 6674 | + } | |
| 6675 | + } | |
| 6676 | + | |
| 6677 | + function uninstallNow() { | |
| 6678 | + /*jshint validthis:true */ | |
| 6679 | + if ( confirmLinkClick( this ) === true ) { | |
| 6680 | + jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' ); | |
| 6681 | + jQuery.ajax({ | |
| 6682 | + type: 'POST', | |
| 6683 | + url: ajaxurl, | |
| 6684 | + data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce, | |
| 6685 | + success: function( msg ) { | |
| 6686 | + jQuery( '.frm_uninstall' ).fadeOut( 'slow' ); | |
| 6687 | + window.location = msg; | |
| 6688 | + } | |
| 6689 | + }); | |
| 6690 | + } | |
| 6691 | + return false; | |
| 6692 | + } | |
| 6693 | + | |
| 6694 | + function saveAddonLicense() { | |
| 6695 | + /*jshint validthis:true */ | |
| 6696 | + var button = jQuery( this ); | |
| 6697 | + var buttonName = this.name; | |
| 6698 | + var pluginSlug = this.getAttribute( 'data-plugin' ); | |
| 6699 | + var action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' ); | |
| 6700 | + var license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value; | |
| 6701 | + jQuery.ajax({ | |
| 6702 | + type: 'POST', url: ajaxurl, dataType: 'json', | |
| 6703 | + data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce}, | |
| 6704 | + success: function( msg ) { | |
| 6705 | + var thisRow = button.closest( '.edd_frm_license_row' ); | |
| 6706 | + if ( action === 'deactivate' ) { | |
| 6707 | + license = ''; | |
| 6708 | + document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = ''; | |
| 6709 | + } | |
| 6710 | + thisRow.find( '.edd_frm_license' ).html( license ); | |
| 6711 | + if ( msg.success === true ) { | |
| 6712 | + thisRow.find( '.frm_icon_font' ).removeClass( 'frm_hidden' ); | |
| 6713 | + thisRow.find( 'div.alignleft' ).toggleClass( 'frm_hidden', 1000 ); | |
| 6714 | + } | |
| 6715 | + | |
| 6716 | + var messageBox = thisRow.find( '.frm_license_msg' ); | |
| 6717 | + messageBox.html( msg.message ); | |
| 6718 | + if ( msg.message !== '' ) { | |
| 6719 | + setTimeout( function() { | |
| 6720 | + messageBox.html( '' ); | |
| 6721 | + }, 15000 ); | |
| 6722 | + } | |
| 6723 | + } | |
| 6724 | + }); | |
| 6725 | + } | |
| 6726 | + | |
| 6727 | + /* Import/Export page */ | |
| 6728 | + | |
| 6729 | + function startFormMigration( event ) { | |
| 6730 | + event.preventDefault(); | |
| 6731 | + | |
| 6732 | + var checkedBoxes = jQuery( event.target ).find( 'input:checked' ); | |
| 6733 | + if ( ! checkedBoxes.length ) { | |
| 6734 | + return; | |
| 6735 | + } | |
| 6736 | + | |
| 6737 | + var ids = []; | |
| 6738 | + checkedBoxes.each( function( i ) { | |
| 6739 | + ids[i] = this.value; | |
| 6740 | + }); | |
| 6741 | + | |
| 6742 | + // Begin the import process. | |
| 6743 | + importForms( ids, event.target ); | |
| 6744 | + } | |
| 6745 | + | |
| 6746 | + /** | |
| 6747 | + * Begins the process of importing the forms. | |
| 6748 | + */ | |
| 6749 | + function importForms( forms, targetForm ) { | |
| 6750 | + | |
| 6751 | + // Hide the form select section. | |
| 6752 | + var $form = jQuery( targetForm ), | |
| 6753 | + $processSettings = $form.next( '.frm-importer-process' ); | |
| 6754 | + | |
| 6755 | + // Display total number of forms we have to import. | |
| 6756 | + $processSettings.find( '.form-total' ).text( forms.length ); | |
| 6757 | + $processSettings.find( '.form-current' ).text( '1' ); | |
| 6758 | + | |
| 6759 | + $form.hide(); | |
| 6760 | + | |
| 6761 | + // Show processing status. | |
| 6762 | + // '.process-completed' might have been shown earlier during a previous import, so hide now. | |
| 6763 | + $processSettings.find( '.process-completed' ).hide(); | |
| 6764 | + $processSettings.show(); | |
| 6765 | + | |
| 6766 | + // Create global import queue. | |
| 6767 | + s.importQueue = forms; | |
| 6768 | + s.imported = 0; | |
| 6769 | + | |
| 6770 | + // Import the first form in the queue. | |
| 6771 | + importForm( $processSettings ); | |
| 6772 | + } | |
| 6773 | + | |
| 6774 | + /** | |
| 6775 | + * Imports a single form from the import queue. | |
| 6776 | + */ | |
| 6777 | + function importForm( $processSettings ) { | |
| 6778 | + var formID = s.importQueue[0], | |
| 6779 | + provider = $processSettings.closest( '.welcome-panel-content' ).find( 'input[name="slug"]' ).val(), | |
| 6780 | + data = { | |
| 6781 | + action: 'frm_import_' + provider, | |
| 6782 | + form_id: formID, | |
| 6783 | + nonce: frmGlobal.nonce | |
| 6784 | + }; | |
| 6785 | + | |
| 6786 | + // Trigger AJAX import for this form. | |
| 6787 | + jQuery.post( ajaxurl, data, function( res ) { | |
| 6788 | + | |
| 6789 | + if ( res.success ) { | |
| 6790 | + var statusUpdate; | |
| 6791 | + | |
| 6792 | + if ( res.data.error ) { | |
| 6793 | + statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>'; | |
| 6794 | + } else { | |
| 6795 | + statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>'; | |
| 6796 | + } | |
| 6797 | + | |
| 6798 | + $processSettings.find( '.status' ).prepend( statusUpdate ); | |
| 6799 | + $processSettings.find( '.status' ).show(); | |
| 6800 | + | |
| 6801 | + // Remove this form ID from the queue. | |
| 6802 | + s.importQueue = jQuery.grep( s.importQueue, function( value ) { | |
| 6803 | + return value != formID; | |
| 6804 | + }); | |
| 6805 | + s.imported++; | |
| 6806 | + | |
| 6807 | + if ( s.importQueue.length === 0 ) { | |
| 6808 | + $processSettings.find( '.process-count' ).hide(); | |
| 6809 | + $processSettings.find( '.forms-completed' ).text( s.imported ); | |
| 6810 | + $processSettings.find( '.process-completed' ).show(); | |
| 6811 | + } else { | |
| 6812 | + // Import next form in the queue. | |
| 6813 | + $processSettings.find( '.form-current' ).text( s.imported + 1 ); | |
| 6814 | + importForm( $processSettings ); | |
| 6815 | + } | |
| 6816 | + } | |
| 6817 | + }); | |
| 6818 | + } | |
| 6819 | + | |
| 6820 | + function validateExport( e ) { | |
| 6821 | + /*jshint validthis:true */ | |
| 6822 | + e.preventDefault(); | |
| 6823 | + | |
| 6824 | + var s = false; | |
| 6825 | + var $exportForms = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 6826 | + | |
| 6827 | + if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) { | |
| 6828 | + $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' ); | |
| 6829 | + s = 'stop'; | |
| 6830 | + } | |
| 6831 | + | |
| 6832 | + var $exportType = jQuery( 'input[name="type[]"]' ); | |
| 6833 | + if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) { | |
| 6834 | + $exportType.closest( 'p' ).addClass( 'frm_blank_field' ); | |
| 6835 | + s = 'stop'; | |
| 6836 | + } | |
| 6837 | + | |
| 6838 | + if ( s === 'stop' ) { | |
| 6839 | + return false; | |
| 6840 | + } | |
| 6841 | + | |
| 6842 | + e.stopPropagation(); | |
| 6843 | + this.submit(); | |
| 6844 | + } | |
| 6845 | + | |
| 6846 | + function removeExportError() { | |
| 6847 | + /*jshint validthis:true */ | |
| 6848 | + var t = jQuery( this ).closest( '.frm_blank_field' ); | |
| 6849 | + if ( typeof t === 'undefined' ) { | |
| 6850 | + return; | |
| 6851 | + } | |
| 6852 | + | |
| 6853 | + var $thisName = this.name; | |
| 6854 | + if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) { | |
| 6855 | + t.removeClass( 'frm_blank_field' ); | |
| 6856 | + } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) { | |
| 6857 | + t.removeClass( 'frm_blank_field' ); | |
| 6858 | + } | |
| 6859 | + | |
| 6860 | + } | |
| 6861 | + | |
| 6862 | + function checkCSVExtension() { | |
| 6863 | + /*jshint validthis:true */ | |
| 6864 | + var f = jQuery( this ).val(); | |
| 6865 | + var re = /\.csv$/i; | |
| 6866 | + if ( f.match( re ) !== null ) { | |
| 6867 | + jQuery( '.show_csv' ).fadeIn(); | |
| 6868 | + } else { | |
| 6869 | + jQuery( '.show_csv' ).fadeOut(); | |
| 6870 | + } | |
| 6871 | + } | |
| 6872 | + | |
| 6873 | + function checkExportTypes() { | |
| 6874 | + /*jshint validthis:true */ | |
| 6875 | + var $dropdown = jQuery( this ); | |
| 6876 | + var $selected = $dropdown.find( ':selected' ); | |
| 6877 | + var s = $selected.data( 'support' ); | |
| 6878 | + | |
| 6879 | + var multiple = s.indexOf( '|' ); | |
| 6880 | + jQuery( 'input[name="type[]"]' ).each( function() { | |
| 6881 | + this.checked = false; | |
| 6882 | + if ( s.indexOf( this.value ) >= 0 ) { | |
| 6883 | + this.disabled = false; | |
| 6884 | + if ( multiple === -1 ) { | |
| 6885 | + this.checked = true; | |
| 6886 | + } | |
| 6887 | + } else { | |
| 6888 | + this.disabled = true; | |
| 6889 | + } | |
| 6890 | + }); | |
| 6891 | + | |
| 6892 | + if ( $dropdown.val() === 'csv' ) { | |
| 6893 | + jQuery( '.csv_opts' ).show(); | |
| 6894 | + jQuery( '.xml_opts' ).hide(); | |
| 6895 | + } else { | |
| 6896 | + jQuery( '.csv_opts' ).hide(); | |
| 6897 | + jQuery( '.xml_opts' ).show(); | |
| 6898 | + } | |
| 6899 | + | |
| 6900 | + var c = $selected.data( 'count' ); | |
| 6901 | + var exportField = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 6902 | + if ( c === 'single' ) { | |
| 6903 | + exportField.prop( 'multiple', false ); | |
| 6904 | + exportField.prop( 'checked', false ); | |
| 6905 | + } else { | |
| 6906 | + exportField.prop( 'multiple', true ); | |
| 6907 | + exportField.prop( 'disabled', false ); | |
| 6908 | + } | |
| 6909 | + } | |
| 6910 | + | |
| 6911 | + function preventMultipleExport() { | |
| 6912 | + var type = jQuery( 'select[name=format]' ), | |
| 6913 | + selected = type.find( ':selected' ), | |
| 6914 | + count = selected.data( 'count' ), | |
| 6915 | + exportField = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 6916 | + | |
| 6917 | + if ( count === 'single' ) { | |
| 6918 | + // Disable all other fields to prevent multiple selections. | |
| 6919 | + if ( this.checked ) { | |
| 6920 | + exportField.prop( 'disabled', true ); | |
| 6921 | + this.removeAttribute( 'disabled' ); | |
| 6922 | + } else { | |
| 6923 | + exportField.prop( 'disabled', false ); | |
| 6924 | + } | |
| 6925 | + } else { | |
| 6926 | + exportField.prop( 'disabled', false ); | |
| 6927 | + } | |
| 6928 | + } | |
| 6929 | + | |
| 6930 | + function multiselectAccessibility() { | |
| 6931 | + jQuery( '.multiselect-container' ).find( 'input[type="checkbox"]' ).each( function() { | |
| 6932 | + var checkbox = jQuery( this ); | |
| 6933 | + checkbox.closest( 'a' ).attr( | |
| 6934 | + 'aria-describedby', | |
| 6935 | + checkbox.is( ':checked' ) ? 'frm_press_space_checked' : 'frm_press_space_unchecked' | |
| 6936 | + ); | |
| 6937 | + }); | |
| 6938 | + } | |
| 6939 | + | |
| 6940 | + function initiateMultiselect() { | |
| 6941 | + jQuery( '.frm_multiselect' ).hide().each( function() { | |
| 6942 | + var $select = jQuery( this ), | |
| 6943 | + id = $select.is( '[id]' ) ? $select.attr( 'id' ).replace( '[]', '' ) : false, | |
| 6944 | + labelledBy = id ? jQuery( '#for_' + id ) : false; | |
| 6945 | + labelledBy = id && labelledBy.length ? 'aria-labelledby="' + labelledBy.attr( 'id' ) + '"' : ''; | |
| 6946 | + $select.multiselect({ | |
| 6947 | + templates: { | |
| 6948 | + ul: '<ul class="multiselect-container frm-dropdown-menu"></ul>', | |
| 6949 | + li: '<li><a tabindex="0"><label></label></a></li>', | |
| 6950 | + button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown" aria-describedby="frm_multiselect_button" ' + labelledBy + '><span class="multiselect-selected-text"></span> <b class="caret"></b></button>' | |
| 6951 | + }, | |
| 6952 | + buttonContainer: '<div class="btn-group frm-btn-group dropdown" />', | |
| 6953 | + nonSelectedText: '', | |
| 6954 | + onDropdownShown: function( event ) { | |
| 6955 | + var action = jQuery( event.currentTarget.closest( '.frm_form_action_settings, #frm-show-fields' ) ); | |
| 6956 | + if ( action.length ) { | |
| 6957 | + jQuery( '#wpcontent' ).on( 'click', function() { | |
| 6958 | + if ( jQuery( '.multiselect-container.frm-dropdown-menu' ).is( ':visible' ) ) { | |
| 6959 | + jQuery( event.currentTarget ).removeClass( 'open' ); | |
| 6960 | + } | |
| 6961 | + }); | |
| 6962 | + } | |
| 6963 | + | |
| 6964 | + multiselectAccessibility(); | |
| 6965 | + }, | |
| 6966 | + onChange: function( element, option ) { | |
| 6967 | + multiselectAccessibility(); | |
| 6968 | + $select.trigger( 'frm-multiselect-changed', element, option ); | |
| 6969 | + } | |
| 6970 | + }); | |
| 6971 | + }); | |
| 6972 | + } | |
| 6973 | + | |
| 6974 | + /* Addons page */ | |
| 6975 | + function installMultipleAddons( e ) { | |
| 6976 | + e.preventDefault(); | |
| 6977 | + installOrActivate( this, 'frm_multiple_addons' ); | |
| 6978 | + } | |
| 6979 | + | |
| 6980 | + function activateAddon( e ) { | |
| 6981 | + e.preventDefault(); | |
| 6982 | + installOrActivate( this, 'frm_activate_addon' ); | |
| 6983 | + } | |
| 6984 | + | |
| 6985 | + function installAddon( e ) { | |
| 6986 | + e.preventDefault(); | |
| 6987 | + installOrActivate( this, 'frm_install_addon' ); | |
| 6988 | + } | |
| 6989 | + | |
| 6990 | + function installOrActivate( clicked, action ) { | |
| 6991 | + // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated. | |
| 6992 | + jQuery( '.frm-addon-error' ).remove(); | |
| 6993 | + var button = jQuery( clicked ); | |
| 6994 | + var plugin = button.attr( 'rel' ); | |
| 6995 | + var el = button.parent(); | |
| 6996 | + var message = el.parent().find( '.addon-status-label' ); | |
| 6997 | + | |
| 6998 | + button.addClass( 'frm_loading_button' ); | |
| 6999 | + | |
| 7000 | + // Process the Ajax to perform the activation. | |
| 7001 | + jQuery.ajax({ | |
| 7002 | + url: ajaxurl, | |
| 7003 | + type: 'POST', | |
| 7004 | + async: true, | |
| 7005 | + cache: false, | |
| 7006 | + dataType: 'json', | |
| 7007 | + data: { | |
| 7008 | + action: action, | |
| 7009 | + nonce: frmGlobal.nonce, | |
| 7010 | + plugin: plugin | |
| 7011 | + }, | |
| 7012 | + success: function( response ) { | |
| 7013 | + var error = extractErrorFromAddOnResponse( response ); | |
| 7014 | + | |
| 7015 | + if ( error ) { | |
| 7016 | + addonError( error, el, button ); | |
| 7017 | + return; | |
| 7018 | + } | |
| 7019 | + | |
| 7020 | + afterAddonInstall( response, button, message, el ); | |
| 7021 | + }, | |
| 7022 | + error: function() { | |
| 7023 | + button.removeClass( 'frm_loading_button' ); | |
| 7024 | + } | |
| 7025 | + }); | |
| 7026 | + } | |
| 7027 | + | |
| 7028 | + function installAddonWithCreds( e ) { | |
| 7029 | + // Prevent the default action, let the user know we are attempting to install again and go with it. | |
| 7030 | + e.preventDefault(); | |
| 7031 | + | |
| 7032 | + // Now let's make another Ajax request once the user has submitted their credentials. | |
| 7033 | + var proceed = jQuery( this ), | |
| 7034 | + el = proceed.parent().parent(), | |
| 7035 | + plugin = proceed.attr( 'rel' ); | |
| 7036 | + | |
| 7037 | + proceed.addClass( 'frm_loading_button' ); | |
| 7038 | + | |
| 7039 | + jQuery.ajax({ | |
| 7040 | + url: ajaxurl, | |
| 7041 | + type: 'POST', | |
| 7042 | + async: true, | |
| 7043 | + cache: false, | |
| 7044 | + dataType: 'json', | |
| 7045 | + data: { | |
| 7046 | + action: 'frm_install_addon', | |
| 7047 | + nonce: frm_admin_js.nonce, | |
| 7048 | + plugin: plugin, | |
| 7049 | + hostname: el.find( '#hostname' ).val(), | |
| 7050 | + username: el.find( '#username' ).val(), | |
| 7051 | + password: el.find( '#password' ).val() | |
| 7052 | + }, | |
| 7053 | + success: function( response ) { | |
| 7054 | + var error = extractErrorFromAddOnResponse( response ); | |
| 7055 | + | |
| 7056 | + if ( error ) { | |
| 7057 | + addonError( error, el, proceed ); | |
| 7058 | + return; | |
| 7059 | + } | |
| 7060 | + | |
| 7061 | + afterAddonInstall( response, proceed, message, el ); | |
| 7062 | + }, | |
| 7063 | + error: function() { | |
| 7064 | + proceed.removeClass( 'frm_loading_button' ); | |
| 7065 | + } | |
| 7066 | + }); | |
| 7067 | + } | |
| 7068 | + | |
| 7069 | + function afterAddonInstall( response, button, message, el ) { | |
| 7070 | + // The Ajax request was successful, so let's update the output. | |
| 7071 | + button.css({ 'opacity': '0' }); | |
| 7072 | + message.text( frm_admin_js.active ); | |
| 7073 | + jQuery( '#frm-oneclick' ).hide(); | |
| 7074 | + jQuery( '#frm-addon-status' ).text( response ).show(); | |
| 7075 | + jQuery( '#frm_upgrade_modal h2' ).hide(); | |
| 7076 | + jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' ); | |
| 7077 | + jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' ); | |
| 7078 | + | |
| 7079 | + // Proceed with CSS changes | |
| 7080 | + el.parent().removeClass( 'frm-addon-not-installed frm-addon-installed' ).addClass( 'frm-addon-active' ); | |
| 7081 | + button.removeClass( 'frm_loading_button' ); | |
| 7082 | + | |
| 7083 | + // Maybe refresh import and SMTP pages | |
| 7084 | + var refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' ); | |
| 7085 | + if ( refreshPage.length > 0 ) { | |
| 7086 | + window.location.reload(); | |
| 7087 | + } | |
| 7088 | + } | |
| 7089 | + | |
| 7090 | + function extractErrorFromAddOnResponse( response ) { | |
| 7091 | + var $message, text; | |
| 7092 | + | |
| 7093 | + if ( typeof response !== 'string' ) { | |
| 7094 | + if ( typeof response.success !== 'undefined' && response.success ) { | |
| 7095 | + return false; | |
| 7096 | + } | |
| 7097 | + | |
| 7098 | + if ( response.form ) { | |
| 7099 | + if ( jQuery( response.form ).is( '#message' ) ) { | |
| 7100 | + return { | |
| 7101 | + message: jQuery( response.form ).find( 'p' ).html() | |
| 7102 | + }; | |
| 7103 | + } | |
| 7104 | + } | |
| 7105 | + | |
| 7106 | + return response; | |
| 7107 | + } | |
| 7108 | + | |
| 7109 | + return false; | |
| 7110 | + } | |
| 7111 | + | |
| 7112 | + function addonError( response, el, button ) { | |
| 7113 | + if ( response.form ) { | |
| 7114 | + jQuery( '.frm-inline-error' ).remove(); | |
| 7115 | + button.closest( '.frm-card' ) | |
| 7116 | + .html( response.form ) | |
| 7117 | + .css({ padding: 5 }) | |
| 7118 | + .find( '#upgrade' ) | |
| 7119 | + .attr( 'rel', button.attr( 'rel' ) ) | |
| 7120 | + .on( 'click', installAddonWithCreds ); | |
| 7121 | + } else { | |
| 7122 | + el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' ); | |
| 7123 | + button.removeClass( 'frm_loading_button' ); | |
| 7124 | + jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut(); | |
| 7125 | + } | |
| 7126 | + } | |
| 7127 | + | |
| 7128 | + /* Templates */ | |
| 7129 | + | |
| 7130 | + function initNewFormModal() { | |
| 7131 | + var installFormTrigger, | |
| 7132 | + activeHoverIcons, | |
| 7133 | + $modal, | |
| 7134 | + handleError, | |
| 7135 | + handleEmailAddressError, | |
| 7136 | + handleConfirmEmailAddressError, | |
| 7137 | + showFreeTemplatesForm, | |
| 7138 | + firstLockedTemplate, | |
| 7139 | + isShowFreeTemplatesFormFirst, | |
| 7140 | + url, | |
| 7141 | + urlParams; | |
| 7142 | + | |
| 7143 | + url = new URL( window.location.href ); | |
| 7144 | + urlParams = url.searchParams; | |
| 7145 | + | |
| 7146 | + isShowFreeTemplatesFormFirst = urlParams.get( 'free-templates' ); | |
| 7147 | + | |
| 7148 | + jQuery( document ).on( 'click', '.frm-trigger-new-form-modal', triggerNewFormModal ); | |
| 7149 | + $modal = initModal( '#frm_new_form_modal', '600px' ); | |
| 7150 | + | |
| 7151 | + installFormTrigger = document.createElement( 'a' ); | |
| 7152 | + installFormTrigger.classList.add( 'frm-install-template', 'frm_hidden' ); | |
| 7153 | + document.body.appendChild( installFormTrigger ); | |
| 7154 | + | |
| 7155 | + jQuery( '.frm-install-template' ).on( 'click', function( event ) { | |
| 7156 | + var $h3Clone = jQuery( this ).closest( 'li, td' ).find( 'h3' ).clone(), | |
| 7157 | + nameLabel = document.getElementById( 'frm_new_name' ), | |
| 7158 | + descLabel = document.getElementById( 'frm_new_desc' ), | |
| 7159 | + oldName; | |
| 7160 | + | |
| 7161 | + $h3Clone.find( 'svg, .frm-plan-required-tag' ).remove(); | |
| 7162 | + oldName = $h3Clone.html().trim(); | |
| 7163 | + | |
| 7164 | + event.preventDefault(); | |
| 7165 | + | |
| 7166 | + document.getElementById( 'frm_template_name' ).value = oldName; | |
| 7167 | + document.getElementById( 'frm_link' ).value = this.attributes.rel.value; | |
| 7168 | + document.getElementById( 'frm_action_type' ).value = 'frm_install_template'; | |
| 7169 | + nameLabel.innerHTML = nameLabel.getAttribute( 'data-form' ); | |
| 7170 | + descLabel.innerHTML = descLabel.getAttribute( 'data-form' ); | |
| 7171 | + $modal.dialog( 'open' ); | |
| 7172 | + }); | |
| 7173 | + | |
| 7174 | + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate ); | |
| 7175 | + | |
| 7176 | + jQuery( document ).on( 'click', '.frm-hover-icons .frm-preview-form', function( event ) { | |
| 7177 | + var $li, link, iframe, | |
| 7178 | + container = document.getElementById( 'frm-preview-block' ); | |
| 7179 | + | |
| 7180 | + event.preventDefault(); | |
| 7181 | + | |
| 7182 | + $li = jQuery( this ).closest( 'li' ); | |
| 7183 | + link = $li.attr( 'data-preview' ); | |
| 7184 | + | |
| 7185 | + if ( link.indexOf( ajaxurl ) > -1 ) { | |
| 7186 | + iframe = document.createElement( 'iframe' ); | |
| 7187 | + iframe.src = link; | |
| 7188 | + iframe.height = '400'; | |
| 7189 | + iframe.width = '100%'; | |
| 7190 | + container.innerHTML = ''; | |
| 7191 | + container.appendChild( iframe ); | |
| 7192 | + } else { | |
| 7193 | + frmApiPreview( container, link ); | |
| 7194 | + } | |
| 7195 | + | |
| 7196 | + jQuery( '#frm-preview-title' ).text( getStrippedTemplateName( $li ) ); | |
| 7197 | + $modal.attr( 'frm-page', 'preview' ); | |
| 7198 | + activeHoverIcons = jQuery( this ).closest( '.frm-hover-icons' ); | |
| 7199 | + }); | |
| 7200 | + | |
| 7201 | + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-create-form', function( event ) { | |
| 7202 | + var $li, name, link, action; | |
| 7203 | + | |
| 7204 | + event.preventDefault(); | |
| 7205 | + | |
| 7206 | + $li = jQuery( this ).closest( 'li' ); | |
| 7207 | + | |
| 7208 | + if ( $li.is( '[data-href]' ) ) { | |
| 7209 | + window.location = $li.attr( 'data-href' ); | |
| 7210 | + return; | |
| 7211 | + } | |
| 7212 | + | |
| 7213 | + if ( $li.hasClass( 'frm-add-blank-form' ) ) { | |
| 7214 | + name = link = ''; | |
| 7215 | + action = 'frm_install_form'; | |
| 7216 | + } else if ( $li.is( '[data-rel]' ) ) { | |
| 7217 | + name = getStrippedTemplateName( $li ); | |
| 7218 | + link = $li.attr( 'data-rel' ); | |
| 7219 | + action = 'frm_install_template'; | |
| 7220 | + } else { | |
| 7221 | + return; | |
| 7222 | + } | |
| 7223 | + | |
| 7224 | + transitionToAddDetails( $modal, name, link, action ); | |
| 7225 | + }); | |
| 7226 | + | |
| 7227 | + // Welcome page modals. | |
| 7228 | + jQuery( document ).on( 'click', '.frm-create-blank-form', function( event ) { | |
| 7229 | + event.preventDefault(); | |
| 7230 | + jQuery( '.frm-trigger-new-form-modal' ).trigger( 'click' ); | |
| 7231 | + transitionToAddDetails( $modal, '', '', 'frm_install_form' ); | |
| 7232 | + | |
| 7233 | + // Close the modal with the cancel button. | |
| 7234 | + jQuery( '.frm-modal-cancel.frm-back-to-all-templates' ).on( 'click', function() { | |
| 7235 | + jQuery( '.ui-widget-overlay' ).trigger( 'click' ); | |
| 7236 | + }); | |
| 7237 | + }); | |
| 7238 | + | |
| 7239 | + 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 ) { | |
| 7240 | + var $hoverIcons, $trigger, | |
| 7241 | + $li = jQuery( this ).closest( 'li' ), | |
| 7242 | + triggerClass = $li.hasClass( 'frm-locked-template' ) ? 'frm-unlock-form' : 'frm-create-form'; | |
| 7243 | + | |
| 7244 | + $hoverIcons = $li.find( '.frm-hover-icons' ); | |
| 7245 | + if ( ! $hoverIcons.length ) { | |
| 7246 | + $li.trigger( 'mouseover' ); | |
| 7247 | + $hoverIcons = $li.find( '.frm-hover-icons' ); | |
| 7248 | + $hoverIcons.hide(); | |
| 7249 | + } | |
| 7250 | + | |
| 7251 | + $trigger = $hoverIcons.find( '.' + triggerClass ); | |
| 7252 | + $trigger.trigger( 'click' ); | |
| 7253 | + }); | |
| 7254 | + | |
| 7255 | + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-delete-form', function( event ) { | |
| 7256 | + var $li, | |
| 7257 | + trigger; | |
| 7258 | + | |
| 7259 | + event.preventDefault(); | |
| 7260 | + | |
| 7261 | + $li = jQuery( this ).closest( 'li' ); | |
| 7262 | + $li.addClass( 'frm-deleting' ); | |
| 7263 | + trigger = document.createElement( 'a' ); | |
| 7264 | + trigger.setAttribute( 'href', '#' ); | |
| 7265 | + trigger.setAttribute( 'data-id', $li.attr( 'data-formid' ) ); | |
| 7266 | + $li.attr( 'id', 'frm-template-custom-' + $li.attr( 'data-formid' ) ); | |
| 7267 | + jQuery( trigger ).on( 'click', trashTemplate ); | |
| 7268 | + trigger.click(); | |
| 7269 | + setTemplateCount( $li.closest( '.accordion-section' ).get( 0 ) ); | |
| 7270 | + }); | |
| 7271 | + | |
| 7272 | + showFreeTemplatesForm = function( $el ) { | |
| 7273 | + var formContainer = document.getElementById( 'frmapi-email-form' ); | |
| 7274 | + jQuery.ajax({ | |
| 7275 | + dataType: 'json', | |
| 7276 | + url: formContainer.getAttribute( 'data-url' ), | |
| 7277 | + success: function( json ) { | |
| 7278 | + var form = json.renderedHtml; | |
| 7279 | + form = form.replace( /<script\b[^<]*(community.formidableforms.com\/wp-includes\/js\/jquery\/jquery)[^<]*><\/script>/gi, '' ); | |
| 7280 | + form = form.replace( /<link\b[^>]*(formidableforms.css)[^>]*>/gi, '' ); | |
| 7281 | + formContainer.innerHTML = form; | |
| 7282 | + } | |
| 7283 | + }); | |
| 7284 | + | |
| 7285 | + $modal.attr( 'frm-page', 'email' ); | |
| 7286 | + $modal.attr( 'frm-this-form', $el.attr( 'data-key' ) ); | |
| 7287 | + $el.append( installFormTrigger ); | |
| 7288 | + }; | |
| 7289 | + | |
| 7290 | + jQuery( document ).on( 'click', 'li.frm-locked-template .frm-hover-icons .frm-unlock-form', function( event ) { | |
| 7291 | + var $li, | |
| 7292 | + activePage; | |
| 7293 | + | |
| 7294 | + event.preventDefault(); | |
| 7295 | + | |
| 7296 | + $li = jQuery( this ).closest( '.frm-locked-template' ); | |
| 7297 | + | |
| 7298 | + if ( $li.hasClass( 'frm-free-template' ) ) { | |
| 7299 | + showFreeTemplatesForm( $li ); | |
| 7300 | + return; | |
| 7301 | + } | |
| 7302 | + | |
| 7303 | + if ( $modal.hasClass( 'frm-expired' ) ) { | |
| 7304 | + activePage = 'renew'; | |
| 7305 | + } else { | |
| 7306 | + activePage = 'upgrade'; | |
| 7307 | + } | |
| 7308 | + | |
| 7309 | + $modal.attr( 'frm-page', activePage ); | |
| 7310 | + }); | |
| 7311 | + | |
| 7312 | + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop', function() { | |
| 7313 | + jQuery( this ) | |
| 7314 | + .closest( '.accordion-section-content' ).css( 'overflow', 'visible' ) | |
| 7315 | + .closest( '.accordion-section' ).css( 'z-index', 1 ); | |
| 7316 | + }); | |
| 7317 | + | |
| 7318 | + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop + ul .frm-build-template', function() { | |
| 7319 | + var name = this.getAttribute( 'data-fullname' ), | |
| 7320 | + link = this.getAttribute( 'data-formid' ), | |
| 7321 | + action = 'frm_build_template'; | |
| 7322 | + transitionToAddDetails( $modal, name, link, action ); | |
| 7323 | + }); | |
| 7324 | + | |
| 7325 | + handleError = function( inputId, errorId, type, message ) { | |
| 7326 | + var $error = jQuery( errorId ); | |
| 7327 | + $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type ); | |
| 7328 | + | |
| 7329 | + if ( typeof message !== 'undefined' ) { | |
| 7330 | + $error.find( 'span[frm-error="' + type + '"]' ).text( message ); | |
| 7331 | + } | |
| 7332 | + | |
| 7333 | + jQuery( inputId ).one( 'keyup', function() { | |
| 7334 | + $error.addClass( 'frm_hidden' ); | |
| 7335 | + }); | |
| 7336 | + }; | |
| 7337 | + | |
| 7338 | + handleEmailAddressError = function( type ) { | |
| 7339 | + handleError( '#frm_leave_email', '#frm_leave_email_error', type ); | |
| 7340 | + }; | |
| 7341 | + | |
| 7342 | + jQuery( document ).on( 'click', '#frm-add-my-email-address', function( event ) { | |
| 7343 | + var email = document.getElementById( 'frm_leave_email' ).value.trim(), | |
| 7344 | + regex, | |
| 7345 | + $hiddenForm, | |
| 7346 | + $hiddenEmailField; | |
| 7347 | + | |
| 7348 | + event.preventDefault(); | |
| 7349 | + | |
| 7350 | + if ( '' === email ) { | |
| 7351 | + handleEmailAddressError( 'empty' ); | |
| 7352 | + return; | |
| 7353 | + } | |
| 7354 | + | |
| 7355 | + 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; | |
| 7356 | + | |
| 7357 | + if ( regex.test( email ) === false ) { | |
| 7358 | + handleEmailAddressError( 'invalid' ); | |
| 7359 | + return; | |
| 7360 | + } | |
| 7361 | + | |
| 7362 | + $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' ); | |
| 7363 | + $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' ); | |
| 7364 | + if ( ! $hiddenEmailField.length ) { | |
| 7365 | + return; | |
| 7366 | + } | |
| 7367 | + | |
| 7368 | + $hiddenEmailField.val( email ); | |
| 7369 | + jQuery.ajax({ | |
| 7370 | + type: 'POST', | |
| 7371 | + url: $hiddenForm.attr( 'action' ), | |
| 7372 | + data: $hiddenForm.serialize() + '&action=frm_forms_preview' | |
| 7373 | + }).done( function( data ) { | |
| 7374 | + var message = jQuery( data ).find( '.frm_message' ).text().trim(); | |
| 7375 | + if ( message.indexOf( 'Thanks!' ) >= 0 ) { | |
| 7376 | + $modal.attr( 'frm-page', 'code' ); | |
| 7377 | + } else { | |
| 7378 | + handleEmailAddressError( 'invalid' ); | |
| 7379 | + } | |
| 7380 | + }); | |
| 7381 | + }); | |
| 7382 | + | |
| 7383 | + handleConfirmEmailAddressError = function( type, message ) { | |
| 7384 | + handleError( '#frm_code_from_email', '#frm_code_from_email_error', type, message ); | |
| 7385 | + }; | |
| 7386 | + | |
| 7387 | + jQuery( document ).on( 'click', '.frm-confirm-email-address', function( event ) { | |
| 7388 | + var code = document.getElementById( 'frm_code_from_email' ).value.trim(); | |
| 7389 | + | |
| 7390 | + event.preventDefault(); | |
| 7391 | + | |
| 7392 | + if ( '' === code ) { | |
| 7393 | + handleConfirmEmailAddressError( 'empty' ); | |
| 7394 | + return; | |
| 7395 | + } | |
| 7396 | + | |
| 7397 | + jQuery.ajax({ | |
| 7398 | + type: 'POST', | |
| 7399 | + url: ajaxurl, | |
| 7400 | + dataType: 'json', | |
| 7401 | + data: { | |
| 7402 | + action: 'template_api_signup', | |
| 7403 | + nonce: frmGlobal.nonce, | |
| 7404 | + code: code, | |
| 7405 | + key: $modal.attr( 'frm-this-form' ) | |
| 7406 | + }, | |
| 7407 | + success: function( response ) { | |
| 7408 | + if ( response.success ) { | |
| 7409 | + if ( isShowFreeTemplatesFormFirst ) { | |
| 7410 | + // Remove free-templates param from URL then reload page. | |
| 7411 | + urlParams.delete( 'free-templates' ); | |
| 7412 | + url.search = urlParams.toString(); | |
| 7413 | + window.location.href = url.toString(); | |
| 7414 | + | |
| 7415 | + return; | |
| 7416 | + } | |
| 7417 | + | |
| 7418 | + if ( typeof response.data !== 'undefined' && typeof response.data.url !== 'undefined' ) { | |
| 7419 | + installFormTrigger.setAttribute( 'rel', response.data.url ); | |
| 7420 | + installFormTrigger.click(); | |
| 7421 | + $modal.attr( 'frm-page', 'details' ); | |
| 7422 | + document.getElementById( 'frm_action_type' ).value = 'frm_install_template'; | |
| 7423 | + | |
| 7424 | + if ( typeof response.data.urlByKey !== 'undefined' ) { | |
| 7425 | + updateTemplateModalFreeUrls( response.data.urlByKey ); | |
| 7426 | + } | |
| 7427 | + } | |
| 7428 | + } else { | |
| 7429 | + if ( Array.isArray( response.data ) && response.data.length ) { | |
| 7430 | + handleConfirmEmailAddressError( 'custom', response.data[0].message ); | |
| 7431 | + } else { | |
| 7432 | + handleConfirmEmailAddressError( 'wrong-code' ); | |
| 7433 | + } | |
| 7434 | + | |
| 7435 | + jQuery( '#frm_code_from_email_options' ).removeClass( 'frm_hidden' ); | |
| 7436 | + } | |
| 7437 | + } | |
| 7438 | + }); | |
| 7439 | + }); | |
| 7440 | + | |
| 7441 | + jQuery( document ).on( 'click', '#frm-change-email-address', function() { | |
| 7442 | + $modal.attr( 'frm-page', 'email' ); | |
| 7443 | + }); | |
| 7444 | + | |
| 7445 | + jQuery( document ).on( 'click', '#frm-resend-code', function() { | |
| 7446 | + document.getElementById( 'frm_code_from_email' ).value = ''; | |
| 7447 | + jQuery( '#frm_code_from_email_options, #frm_code_from_email_error' ).addClass( 'frm_hidden' ); | |
| 7448 | + document.getElementById( 'frm-add-my-email-address' ).click(); | |
| 7449 | + }); | |
| 7450 | + | |
| 7451 | + jQuery( document ).on( 'frmAfterSearch', '#frm_new_form_modal #template-search-input', function() { | |
| 7452 | + var categories = $modal.get( 0 ).querySelector( '.frm-categories-list' ).children, | |
| 7453 | + categoryIndex, | |
| 7454 | + category, | |
| 7455 | + searchableTemplates, | |
| 7456 | + count; | |
| 7457 | + | |
| 7458 | + for ( categoryIndex in categories ) { | |
| 7459 | + if ( isNaN( categoryIndex ) ) { | |
| 7460 | + continue; | |
| 7461 | + } | |
| 7462 | + | |
| 7463 | + category = categories[ categoryIndex ]; | |
| 7464 | + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden)' ); | |
| 7465 | + count = searchableTemplates.length; | |
| 7466 | + jQuery( category ).toggleClass( 'frm_hidden', this.value !== '' && ! count ); | |
| 7467 | + setTemplateCount( category, searchableTemplates ); | |
| 7468 | + } | |
| 7469 | + }); | |
| 7470 | + | |
| 7471 | + 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 ) { | |
| 7472 | + document.getElementById( 'frm-create-title' ).removeAttribute( 'frm-type' ); | |
| 7473 | + $modal.attr( 'frm-page', 'create' ); | |
| 7474 | + }); | |
| 7475 | + | |
| 7476 | + jQuery( document ).on( 'click', '.frm-use-this-template', function( event ) { | |
| 7477 | + var $trigger; | |
| 7478 | + | |
| 7479 | + event.preventDefault(); | |
| 7480 | + | |
| 7481 | + $trigger = activeHoverIcons.find( '.frm-create-form' ); | |
| 7482 | + if ( $trigger.closest( '.frm-selectable' ).hasClass( 'frm-locked-template' ) ) { | |
| 7483 | + $trigger = activeHoverIcons.find( '.frm-unlock-form' ); | |
| 7484 | + } | |
| 7485 | + | |
| 7486 | + $trigger.trigger( 'click' ); | |
| 7487 | + }); | |
| 7488 | + | |
| 7489 | + jQuery( document ).on( 'click', '.frm-submit-new-template', function( event ) { | |
| 7490 | + var button; | |
| 7491 | + event.preventDefault(); | |
| 7492 | + button = document.getElementById( 'frm-new-template' ).querySelector( 'button' ); | |
| 7493 | + if ( null !== button ) { | |
| 7494 | + button.click(); | |
| 7495 | + } | |
| 7496 | + }); | |
| 7497 | + | |
| 7498 | + if ( urlParams.get( 'triggerNewFormModal' ) ) { | |
| 7499 | + triggerNewFormModal(); | |
| 7500 | + | |
| 7501 | + if ( isShowFreeTemplatesFormFirst ) { | |
| 7502 | + firstLockedTemplate = jQuery( 'li.frm-locked-template.frm-free-template' ).eq( 0 ); | |
| 7503 | + | |
| 7504 | + if ( firstLockedTemplate.length ) { | |
| 7505 | + showFreeTemplatesForm( firstLockedTemplate ); | |
| 7506 | + } | |
| 7507 | + } | |
| 7508 | + } | |
| 7509 | + } | |
| 7510 | + | |
| 7511 | + function updateTemplateModalFreeUrls( urlByKey ) { | |
| 7512 | + jQuery( '#frm_new_form_modal' ).find( '.frm-selectable[data-key]' ).each( function() { | |
| 7513 | + var $template = jQuery( this ), | |
| 7514 | + key = $template.attr( 'data-key' ); | |
| 7515 | + if ( 'undefined' !== typeof urlByKey[ key ]) { | |
| 7516 | + $template.removeClass( 'frm-locked-template' ); | |
| 7517 | + $template.find( 'h3 svg' ).remove(); // remove the lock from the title | |
| 7518 | + $template.attr( 'data-rel', urlByKey[ key ]); | |
| 7519 | + } | |
| 7520 | + }); | |
| 7521 | + } | |
| 7522 | + | |
| 7523 | + function transitionToAddDetails( $modal, name, link, action ) { | |
| 7524 | + var nameLabel = document.getElementById( 'frm_new_name' ), | |
| 7525 | + descLabel = document.getElementById( 'frm_new_desc' ), | |
| 7526 | + type = [ 'frm_install_template', 'frm_install_form' ].indexOf( action ) >= 0 ? 'form' : 'template', | |
| 7527 | + templateNameInput = document.getElementById( 'frm_template_name' ); | |
| 7528 | + | |
| 7529 | + templateNameInput.value = name; | |
| 7530 | + document.getElementById( 'frm_link' ).value = link; | |
| 7531 | + document.getElementById( 'frm_action_type' ).value = action; | |
| 7532 | + nameLabel.textContent = nameLabel.getAttribute( 'data-' + type ); | |
| 7533 | + descLabel.textContent = descLabel.getAttribute( 'data-' + type ); | |
| 7534 | + | |
| 7535 | + document.getElementById( 'frm-create-title' ).setAttribute( 'frm-type', type ); | |
| 7536 | + | |
| 7537 | + $modal.attr( 'frm-page', 'details' ); | |
| 7538 | + | |
| 7539 | + if ( '' === name ) { | |
| 7540 | + templateNameInput.focus(); | |
| 7541 | + } | |
| 7542 | + } | |
| 7543 | + | |
| 7544 | + function getStrippedTemplateName( $li ) { | |
| 7545 | + var $clone = $li.find( 'h3' ).clone(); | |
| 7546 | + $clone.find( 'svg, .frm-plan-required-tag' ).remove(); | |
| 7547 | + return $clone.html().trim(); | |
| 7548 | + } | |
| 7549 | + | |
| 7550 | + function setTemplateCount( category, searchableTemplates ) { | |
| 7551 | + var count, | |
| 7552 | + templateIndex, | |
| 7553 | + availableCounter, | |
| 7554 | + availableCount; | |
| 7555 | + | |
| 7556 | + if ( typeof searchableTemplates === 'undefined' ) { | |
| 7557 | + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden):not(.frm-deleting)' ); | |
| 7558 | + } | |
| 7559 | + | |
| 7560 | + count = searchableTemplates.length; | |
| 7561 | + category.querySelector( '.frm-template-count' ).textContent = count; | |
| 7562 | + | |
| 7563 | + jQuery( category ).find( '.frm-templates-plural' ).toggleClass( 'frm_hidden', count === 1 ); | |
| 7564 | + jQuery( category ).find( '.frm-templates-singular' ).toggleClass( 'frm_hidden', count !== 1 ); | |
| 7565 | + | |
| 7566 | + availableCounter = category.querySelector( '.frm-available-templates-count' ); | |
| 7567 | + if ( availableCounter !== null ) { | |
| 7568 | + availableCount = 0; | |
| 7569 | + for ( templateIndex in searchableTemplates ) { | |
| 7570 | + if ( ! isNaN( templateIndex ) && ! searchableTemplates[ templateIndex ].classList.contains( 'frm-locked-template' ) ) { | |
| 7571 | + availableCount++; | |
| 7572 | + } | |
| 7573 | + } | |
| 7574 | + | |
| 7575 | + availableCounter.textContent = availableCount; | |
| 7576 | + } | |
| 7577 | + } | |
| 7578 | + | |
| 7579 | + function initSelectionAutocomplete() { | |
| 7580 | + if ( jQuery.fn.autocomplete ) { | |
| 7581 | + initAutocomplete( 'page' ); | |
| 7582 | + initAutocomplete( 'user' ); | |
| 7583 | + } | |
| 7584 | + } | |
| 7585 | + | |
| 7586 | + /** | |
| 7587 | + * Init autocomplete. | |
| 7588 | + * | |
| 7589 | + * @since 4.10.01 Add container param to init autocomplete elements inside an element. | |
| 7590 | + * | |
| 7591 | + * @param {String} type Type of data. Accepts `page` or `user`. | |
| 7592 | + * @param {String|Object} container Container class or element. Default is null. | |
| 7593 | + */ | |
| 7594 | + function initAutocomplete( type, container ) { | |
| 7595 | + const basedUrlParams = '?action=frm_' + type + '_search&nonce=' + frmGlobal.nonce; | |
| 7596 | + const elements = ! container ? jQuery( '.frm-' + type + '-search' ) : jQuery( container ).find( '.frm-' + type + '-search' ); | |
| 7597 | + | |
| 7598 | + elements.each( function() { | |
| 7599 | + let urlParams = basedUrlParams; | |
| 7600 | + const element = jQuery( this ); | |
| 7601 | + | |
| 7602 | + // Check if a custom post type is specific. | |
| 7603 | + if ( element.attr( 'data-post-type' ) ) { | |
| 7604 | + urlParams += '&post_type=' + element.attr( 'data-post-type' ); | |
| 7605 | + } | |
| 7606 | + element.autocomplete({ | |
| 7607 | + delay: 100, | |
| 7608 | + minLength: 0, | |
| 7609 | + source: ajaxurl + urlParams, | |
| 7610 | + change: autoCompleteSelectBlank, | |
| 7611 | + select: autoCompleteSelectFromResults, | |
| 7612 | + focus: autoCompleteFocus, | |
| 7613 | + position: { | |
| 7614 | + my: 'left top', | |
| 7615 | + at: 'left bottom', | |
| 7616 | + collision: 'flip' | |
| 7617 | + }, | |
| 7618 | + response: function( event, ui ) { | |
| 7619 | + if ( ! ui.content.length ) { | |
| 7620 | + var noResult = { value: '', label: frm_admin_js.no_items_found }; | |
| 7621 | + ui.content.push( noResult ); | |
| 7622 | + } | |
| 7623 | + }, | |
| 7624 | + create: function() { | |
| 7625 | + var $container = jQuery( this ).parent(); | |
| 7626 | + | |
| 7627 | + if ( $container.length === 0 ) { | |
| 7628 | + $container = 'body'; | |
| 7629 | + } | |
| 7630 | + | |
| 7631 | + jQuery( this ).autocomplete( 'option', 'appendTo', $container ); | |
| 7632 | + } | |
| 7633 | + }) | |
| 7634 | + .on( 'focus', function() { | |
| 7635 | + // Show options on click to make it work more like a dropdown. | |
| 7636 | + if ( this.value === '' || this.nextElementSibling.value < 1 ) { | |
| 7637 | + jQuery( this ).autocomplete( 'search', this.value ); | |
| 7638 | + } | |
| 7639 | + }); | |
| 7640 | + }); | |
| 7641 | + } | |
| 7642 | + | |
| 7643 | + /** | |
| 7644 | + * Prevent the value from changing when using keyboard to scroll. | |
| 7645 | + */ | |
| 7646 | + function autoCompleteFocus() { | |
| 7647 | + return false; | |
| 7648 | + } | |
| 7649 | + | |
| 7650 | + function autoCompleteSelectBlank( e, ui ) { | |
| 7651 | + if ( ui.item === null ) { | |
| 7652 | + this.nextElementSibling.value = ''; | |
| 7653 | + } | |
| 7654 | + } | |
| 7655 | + | |
| 7656 | + function autoCompleteSelectFromResults( e, ui ) { | |
| 7657 | + e.preventDefault(); | |
| 7658 | + | |
| 7659 | + if ( ui.item.value === '' ) { | |
| 7660 | + this.value = ''; | |
| 7661 | + } else { | |
| 7662 | + this.value = ui.item.label; | |
| 7663 | + } | |
| 7664 | + | |
| 7665 | + this.nextElementSibling.value = ui.item.value; | |
| 7666 | + } | |
| 7667 | + | |
| 7668 | + function nextInstallStep( thisStep ) { | |
| 7669 | + thisStep.classList.add( 'frm_grey' ); | |
| 7670 | + thisStep.nextElementSibling.classList.remove( 'frm_grey' ); | |
| 7671 | + } | |
| 7672 | + | |
| 7673 | + function frmApiPreview( cont, link ) { | |
| 7674 | + cont.innerHTML = '<div class="frm-wait"></div>'; | |
| 7675 | + jQuery.ajax({ | |
| 7676 | + dataType: 'json', | |
| 7677 | + url: link, | |
| 7678 | + success: function( json ) { | |
| 7679 | + var form = json.renderedHtml; | |
| 7680 | + form = form.replace( /<script\b[^<]*(js\/jquery\/jquery)[^<]*><\/script>/gi, '' ); | |
| 7681 | + form = form.replace( /<link\b[^>]*(jquery-ui.min.css)[^>]*>/gi, '' ); | |
| 7682 | + form = form.replace( ' frm_logic_form ', ' ' ); | |
| 7683 | + form = form.replace( '<form ', '<form onsubmit="event.preventDefault();" ' ); | |
| 7684 | + cont.innerHTML = '<div class="frm-wait" id="frm-remove-me"></div><div class="frm-fade" id="frm-show-me">' + | |
| 7685 | + form + '</div>'; | |
| 7686 | + setTimeout( function() { | |
| 7687 | + document.getElementById( 'frm-remove-me' ).style.display = 'none'; | |
| 7688 | + document.getElementById( 'frm-show-me' ).style.opacity = '1'; | |
| 7689 | + }, 300 ); | |
| 7690 | + } | |
| 7691 | + }); | |
| 7692 | + } | |
| 7693 | + | |
| 7694 | + function installTemplateFieldset( e ) { | |
| 7695 | + /*jshint validthis:true */ | |
| 7696 | + var fieldset = this.parentNode.parentNode, | |
| 7697 | + action = fieldset.elements.type.value, | |
| 7698 | + button = this; | |
| 7699 | + e.preventDefault(); | |
| 7700 | + button.classList.add( 'frm_loading_button' ); | |
| 7701 | + installNewForm( fieldset, action, button ); | |
| 7702 | + } | |
| 7703 | + | |
| 7704 | + function installTemplate( e ) { | |
| 7705 | + /*jshint validthis:true */ | |
| 7706 | + var action = this.elements.type.value, | |
| 7707 | + button = this.querySelector( 'button' ); | |
| 7708 | + e.preventDefault(); | |
| 7709 | + button.classList.add( 'frm_loading_button' ); | |
| 7710 | + installNewForm( this, action, button ); | |
| 7711 | + } | |
| 7712 | + | |
| 7713 | + function installNewForm( form, action, button ) { | |
| 7714 | + var data, redirect, href, showError, | |
| 7715 | + formData = formToData( form ), | |
| 7716 | + formName = formData.template_name, | |
| 7717 | + formDesc = formData.template_desc, | |
| 7718 | + link = form.elements.link.value; | |
| 7719 | + | |
| 7720 | + data = { | |
| 7721 | + action: action, | |
| 7722 | + xml: link, | |
| 7723 | + name: formName, | |
| 7724 | + desc: formDesc, | |
| 7725 | + form: JSON.stringify( formData ), | |
| 7726 | + nonce: frmGlobal.nonce | |
| 7727 | + }; | |
| 7728 | + postAjax( data, function( response ) { | |
| 7729 | + redirect = response.redirect; | |
| 7730 | + if ( typeof redirect !== 'undefined' ) { | |
| 7731 | + if ( typeof form.elements.redirect === 'undefined' ) { | |
| 7732 | + window.location = redirect; | |
| 7733 | + } else { | |
| 7734 | + href = document.getElementById( 'frm-redirect-link' ); | |
| 7735 | + if ( typeof link !== 'undefined' && href !== null ) { | |
| 7736 | + // Show the next installation step. | |
| 7737 | + href.setAttribute( 'href', redirect ); | |
| 7738 | + href.classList.remove( 'frm_grey', 'disabled' ); | |
| 7739 | + nextInstallStep( form.parentNode.parentNode ); | |
| 7740 | + button.classList.add( 'frm_grey', 'disabled' ); | |
| 7741 | + } | |
| 7742 | + } | |
| 7743 | + } else { | |
| 7744 | + jQuery( '.spinner' ).css( 'visibility', 'hidden' ); | |
| 7745 | + | |
| 7746 | + // Show response.message | |
| 7747 | + if ( response.message && typeof form.elements.show_response !== 'undefined' ) { | |
| 7748 | + showError = document.getElementById( form.elements.show_response.value ); | |
| 7749 | + if ( showError !== null ) { | |
| 7750 | + showError.innerHTML = response.message; | |
| 7751 | + showError.classList.remove( 'frm_hidden' ); | |
| 7752 | + } | |
| 7753 | + } | |
| 7754 | + } | |
| 7755 | + button.classList.remove( 'frm_loading_button' ); | |
| 7756 | + }); | |
| 7757 | + } | |
| 7758 | + | |
| 7759 | + function trashTemplate( e ) { | |
| 7760 | + /*jshint validthis:true */ | |
| 7761 | + var id = this.getAttribute( 'data-id' ); | |
| 7762 | + e.preventDefault(); | |
| 7763 | + | |
| 7764 | + data = { | |
| 7765 | + action: 'frm_forms_trash', | |
| 7766 | + id: id, | |
| 7767 | + nonce: frmGlobal.nonce | |
| 7768 | + }; | |
| 7769 | + postAjax( data, function() { | |
| 7770 | + var card = document.getElementById( 'frm-template-custom-' + id ); | |
| 7771 | + fadeOut( card, function() { | |
| 7772 | + card.parentNode.removeChild( card ); | |
| 7773 | + }); | |
| 7774 | + }); | |
| 7775 | + } | |
| 7776 | + | |
| 7777 | + function searchContent() { | |
| 7778 | + /*jshint validthis:true */ | |
| 7779 | + var i, | |
| 7780 | + regEx = false, | |
| 7781 | + searchText = this.value.toLowerCase(), | |
| 7782 | + toSearch = this.getAttribute( 'data-tosearch' ), | |
| 7783 | + items = document.getElementsByClassName( toSearch ); | |
| 7784 | + | |
| 7785 | + if ( this.tagName === 'SELECT' ) { | |
| 7786 | + searchText = selectedOptions( this ); | |
| 7787 | + searchText = searchText.join( '|' ).toLowerCase(); | |
| 7788 | + regEx = true; | |
| 7789 | + } | |
| 7790 | + | |
| 7791 | + if ( toSearch === 'frm-action' && searchText !== '' ) { | |
| 7792 | + var addons = document.getElementById( 'frm_email_addon_menu' ).classList; | |
| 7793 | + addons.remove( 'frm-all-actions' ); | |
| 7794 | + addons.add( 'frm-limited-actions' ); | |
| 7795 | + } | |
| 7796 | + | |
| 7797 | + for ( i = 0; i < items.length; i++ ) { | |
| 7798 | + var innerText = items[i].innerText.toLowerCase(); | |
| 7799 | + if ( searchText === '' ) { | |
| 7800 | + items[i].classList.remove( 'frm_hidden' ); | |
| 7801 | + items[i].classList.remove( 'frm-search-result' ); | |
| 7802 | + } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 ) { | |
| 7803 | + items[i].classList.remove( 'frm_hidden' ); | |
| 7804 | + items[i].classList.add( 'frm-search-result' ); | |
| 7805 | + } else { | |
| 7806 | + items[i].classList.add( 'frm_hidden' ); | |
| 7807 | + items[i].classList.remove( 'frm-search-result' ); | |
| 7808 | + } | |
| 7809 | + } | |
| 7810 | + | |
| 7811 | + jQuery( this ).trigger( 'frmAfterSearch' ); | |
| 7812 | + } | |
| 7813 | + | |
| 7814 | + function stopPropagation( e ) { | |
| 7815 | + e.stopPropagation(); | |
| 7816 | + } | |
| 7817 | + | |
| 7818 | + /* Helpers */ | |
| 7819 | + | |
| 7820 | + function selectedOptions( select ) { | |
| 7821 | + var opt, | |
| 7822 | + result = [], | |
| 7823 | + options = select && select.options; | |
| 7824 | + | |
| 7825 | + for ( var i = 0, iLen = options.length; i < iLen; i++ ) { | |
| 7826 | + opt = options[i]; | |
| 7827 | + | |
| 7828 | + if ( opt.selected ) { | |
| 7829 | + result.push( opt.value ); | |
| 7830 | + } | |
| 7831 | + } | |
| 7832 | + return result; | |
| 7833 | + } | |
| 7834 | + | |
| 7835 | + function triggerEvent( element, event ) { | |
| 7836 | + var evt = document.createEvent( 'HTMLEvents' ); | |
| 7837 | + evt.initEvent( event, false, true ); | |
| 7838 | + element.dispatchEvent( evt ); | |
| 7839 | + } | |
| 7840 | + | |
| 7841 | + function postAjax( data, success ) { | |
| 7842 | + var response, params, | |
| 7843 | + xmlHttp = new XMLHttpRequest(); | |
| 7844 | + | |
| 7845 | + params = typeof data === 'string' ? data : Object.keys( data ).map( | |
| 7846 | + function( k ) { | |
| 7847 | + return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]); | |
| 7848 | + } | |
| 7849 | + ).join( '&' ); | |
| 7850 | + | |
| 7851 | + xmlHttp.open( 'post', ajaxurl, true ); | |
| 7852 | + xmlHttp.onreadystatechange = function() { | |
| 7853 | + if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) { | |
| 7854 | + response = xmlHttp.responseText; | |
| 7855 | + try { | |
| 7856 | + response = JSON.parse( response ); | |
| 7857 | + } catch ( e ) { | |
| 7858 | + // The response may not be JSON, so just return it. | |
| 7859 | + } | |
| 7860 | + success( response ); | |
| 7861 | + } | |
| 7862 | + }; | |
| 7863 | + xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' ); | |
| 7864 | + xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' ); | |
| 7865 | + xmlHttp.send( params ); | |
| 7866 | + return xmlHttp; | |
| 7867 | + } | |
| 7868 | + | |
| 7869 | + function fadeOut( element, success ) { | |
| 7870 | + element.classList.add( 'frm-fade' ); | |
| 7871 | + setTimeout( success, 1000 ); | |
| 7872 | + } | |
| 7873 | + | |
| 7874 | + function invisible( classes ) { | |
| 7875 | + jQuery( classes ).css( 'visibility', 'hidden' ); | |
| 7876 | + } | |
| 7877 | + | |
| 7878 | + function visible( classes ) { | |
| 7879 | + jQuery( classes ).css( 'visibility', 'visible' ); | |
| 7880 | + } | |
| 7881 | + | |
| 7882 | + function initModal( id, width ) { | |
| 7883 | + var $info = jQuery( id ); | |
| 7884 | + if ( $info.length < 1 ) { | |
| 7885 | + return false; | |
| 7886 | + } | |
| 7887 | + | |
| 7888 | + if ( typeof width === 'undefined' ) { | |
| 7889 | + width = '550px'; | |
| 7890 | + } | |
| 7891 | + | |
| 7892 | + $info.dialog({ | |
| 7893 | + dialogClass: 'frm-dialog', | |
| 7894 | + modal: true, | |
| 7895 | + autoOpen: false, | |
| 7896 | + closeOnEscape: true, | |
| 7897 | + width: width, | |
| 7898 | + resizable: false, | |
| 7899 | + draggable: false, | |
| 7900 | + open: function() { | |
| 7901 | + jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' ); | |
| 7902 | + jQuery( '#wpwrap' ).addClass( 'frm_overlay' ); | |
| 7903 | + jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' ); | |
| 7904 | + $info.removeClass( 'ui-dialog-content ui-widget-content' ); | |
| 7905 | + bindClickForDialogClose( $info ); | |
| 7906 | + }, | |
| 7907 | + close: function() { | |
| 7908 | + jQuery( '#wpwrap' ).removeClass( 'frm_overlay' ); | |
| 7909 | + jQuery( '.spinner' ).css( 'visibility', 'hidden' ); | |
| 7910 | + } | |
| 7911 | + }); | |
| 7912 | + | |
| 7913 | + return $info; | |
| 7914 | + } | |
| 7915 | + | |
| 7916 | + function toggle( cname, id ) { | |
| 7917 | + if ( id === '#' ) { | |
| 7918 | + var cont = document.getElementById( cname ); | |
| 7919 | + var hidden = cont.style.display; | |
| 7920 | + if ( hidden === 'none' ) { | |
| 7921 | + cont.style.display = 'block'; | |
| 7922 | + } else { | |
| 7923 | + cont.style.display = 'none'; | |
| 7924 | + } | |
| 7925 | + } else { | |
| 7926 | + var vis = cname.is( ':visible' ); | |
| 7927 | + if ( vis ) { | |
| 7928 | + cname.hide(); | |
| 7929 | + } else { | |
| 7930 | + cname.show(); | |
| 7931 | + } | |
| 7932 | + } | |
| 7933 | + } | |
| 7934 | + | |
| 7935 | + function removeWPUnload() { | |
| 7936 | + window.onbeforeunload = null; | |
| 7937 | + var w = jQuery( window ); | |
| 7938 | + w.off( 'beforeunload.widgets' ); | |
| 7939 | + w.off( 'beforeunload.edit-post' ); | |
| 7940 | + } | |
| 7941 | + | |
| 7942 | + function maybeChangeEmbedFormMsg() { | |
| 7943 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 7944 | + var fieldItem = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 7945 | + if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) { | |
| 7946 | + return; | |
| 7947 | + } | |
| 7948 | + | |
| 7949 | + fieldItem = jQuery( fieldItem ); | |
| 7950 | + | |
| 7951 | + if ( this.options[ this.selectedIndex ].value ) { | |
| 7952 | + fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' ); | |
| 7953 | + var embedMsg = fieldItem.find( '.frm-embed-message' ); | |
| 7954 | + embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text ); | |
| 7955 | + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' ); | |
| 7956 | + } else { | |
| 7957 | + fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' ); | |
| 7958 | + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' ); | |
| 7959 | + } | |
| 7960 | + } | |
| 7961 | + | |
| 7962 | + function toggleProductType() { | |
| 7963 | + var settings = jQuery( this ).closest( '.frm-single-settings' ), | |
| 7964 | + container = settings.find( '.frmjs_product_choices' ), | |
| 7965 | + heading = settings.find( '.frm_prod_options_heading' ), | |
| 7966 | + currentVal = this.options[ this.selectedIndex ].value; | |
| 7967 | + | |
| 7968 | + container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' ); | |
| 7969 | + heading.removeClass( 'frm_prod_user_def' ); | |
| 7970 | + | |
| 7971 | + if ( 'single' === currentVal ) { | |
| 7972 | + container.addClass( 'frm_prod_type_single' ); | |
| 7973 | + } else if ( 'user_def' === currentVal ) { | |
| 7974 | + container.addClass( 'frm_prod_type_user_def' ); | |
| 7975 | + heading.addClass( 'frm_prod_user_def' ); | |
| 7976 | + } | |
| 7977 | + } | |
| 7978 | + | |
| 7979 | + function isProductField( fieldId ) { | |
| 7980 | + var field = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 7981 | + if ( field === null ) { | |
| 7982 | + return false; | |
| 7983 | + } else { | |
| 7984 | + return 'product' === field.getAttribute( 'data-type' ); | |
| 7985 | + } | |
| 7986 | + } | |
| 7987 | + | |
| 7988 | + /** | |
| 7989 | + * Serialize form data with vanilla JS. | |
| 7990 | + */ | |
| 7991 | + function formToData( form ) { | |
| 7992 | + var subKey, i, | |
| 7993 | + object = {}, | |
| 7994 | + formData = form.elements; | |
| 7995 | + | |
| 7996 | + for ( i = 0; i < formData.length; i++ ) { | |
| 7997 | + var input = formData[i], | |
| 7998 | + key = input.name, | |
| 7999 | + value = input.value, | |
| 8000 | + names = key.match( /(.*)\[(.*)\]/ ); | |
| 8001 | + | |
| 8002 | + if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) { | |
| 8003 | + continue; | |
| 8004 | + } | |
| 8005 | + | |
| 8006 | + if ( names !== null ) { | |
| 8007 | + key = names[1]; | |
| 8008 | + subKey = names[2]; | |
| 8009 | + if ( ! Reflect.has( object, key ) ) { | |
| 8010 | + object[key] = {}; | |
| 8011 | + } | |
| 8012 | + object[key][subKey] = value; | |
| 8013 | + continue; | |
| 8014 | + } | |
| 8015 | + | |
| 8016 | + // Reflect.has in favor of: object.hasOwnProperty(key) | |
| 8017 | + if ( ! Reflect.has( object, key ) ) { | |
| 8018 | + object[key] = value; | |
| 8019 | + continue; | |
| 8020 | + } | |
| 8021 | + if ( ! Array.isArray( object[key]) ) { | |
| 8022 | + object[key] = [ object[key] ]; | |
| 8023 | + } | |
| 8024 | + object[key].push( value ); | |
| 8025 | + } | |
| 8026 | + | |
| 8027 | + return object; | |
| 8028 | + } | |
| 8029 | + | |
| 8030 | + /** | |
| 8031 | + * Show, hide, and sort subfields of Name field on form builder. | |
| 8032 | + * | |
| 8033 | + * @since 4.11 | |
| 8034 | + */ | |
| 8035 | + function handleNameFieldOnFormBuilder() { | |
| 8036 | + /** | |
| 8037 | + * Gets subfield element from cache. | |
| 8038 | + * | |
| 8039 | + * @param {String} fieldId Field ID. | |
| 8040 | + * @param {String} key Cache key. | |
| 8041 | + * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found. | |
| 8042 | + */ | |
| 8043 | + const getSubFieldElFromCache = ( fieldId, key ) => { | |
| 8044 | + window.frmCachedSubFields = window.frmCachedSubFields || {}; | |
| 8045 | + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {}; | |
| 8046 | + return window.frmCachedSubFields[fieldId][key]; | |
| 8047 | + }; | |
| 8048 | + | |
| 8049 | + /** | |
| 8050 | + * Sets subfield element to cache. | |
| 8051 | + * | |
| 8052 | + * @param {String} fieldId Field ID. | |
| 8053 | + * @param {String} key Cache key. | |
| 8054 | + * @param {HTMLElement} el Element. | |
| 8055 | + */ | |
| 8056 | + const setSubFieldElToCache = ( fieldId, key, el ) => { | |
| 8057 | + window.frmCachedSubFields = window.frmCachedSubFields || {}; | |
| 8058 | + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {}; | |
| 8059 | + window.frmCachedSubFields[fieldId][key] = el; | |
| 8060 | + }; | |
| 8061 | + | |
| 8062 | + /** | |
| 8063 | + * Gets column class from the number of columns. | |
| 8064 | + * | |
| 8065 | + * @param {Number} colCount Number of columns. | |
| 8066 | + * @returns {string} | |
| 8067 | + */ | |
| 8068 | + const getColClass = colCount => 'frm' + parseInt( 12 / colCount ); | |
| 8069 | + | |
| 8070 | + const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num ); | |
| 8071 | + | |
| 8072 | + const allSubFieldNames = [ 'first', 'middle', 'last' ]; | |
| 8073 | + | |
| 8074 | + /** | |
| 8075 | + * Handles name layout change. | |
| 8076 | + * | |
| 8077 | + * @param {Event} event Event object. | |
| 8078 | + */ | |
| 8079 | + const onChangeLayout = event => { | |
| 8080 | + const value = event.target.value; | |
| 8081 | + const subFieldNames = value.split( '_' ); | |
| 8082 | + const fieldId = event.target.dataset.fieldId; | |
| 8083 | + | |
| 8084 | + /* | |
| 8085 | + * Live update form on the form builder. | |
| 8086 | + */ | |
| 8087 | + const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' ); | |
| 8088 | + const newColClass = getColClass( subFieldNames.length ); | |
| 8089 | + | |
| 8090 | + // Set all sub field elements to cache and hide all of them first. | |
| 8091 | + allSubFieldNames.forEach( name => { | |
| 8092 | + const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' ); | |
| 8093 | + if ( subFieldEl ) { | |
| 8094 | + subFieldEl.classList.add( 'frm_hidden' ); | |
| 8095 | + subFieldEl.classList.remove( ...colClasses ); | |
| 8096 | + setSubFieldElToCache( fieldId, name, subFieldEl ); | |
| 8097 | + } | |
| 8098 | + }); | |
| 8099 | + | |
| 8100 | + subFieldNames.forEach( subFieldName => { | |
| 8101 | + const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName ); | |
| 8102 | + if ( ! subFieldEl ) { | |
| 8103 | + return; | |
| 8104 | + } | |
| 8105 | + | |
| 8106 | + subFieldEl.classList.remove( 'frm_hidden' ); | |
| 8107 | + subFieldEl.classList.add( newColClass ); | |
| 8108 | + | |
| 8109 | + container.append( subFieldEl ); | |
| 8110 | + }); | |
| 8111 | + | |
| 8112 | + /* | |
| 8113 | + * Live update subfield options. | |
| 8114 | + */ | |
| 8115 | + // Hide all subfield options. | |
| 8116 | + allSubFieldNames.forEach( name => { | |
| 8117 | + const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' ); | |
| 8118 | + if ( optionsEl ) { | |
| 8119 | + optionsEl.classList.add( 'frm_hidden' ); | |
| 8120 | + setSubFieldElToCache( fieldId, name + '_options', optionsEl ); | |
| 8121 | + } | |
| 8122 | + }); | |
| 8123 | + | |
| 8124 | + subFieldNames.forEach( subFieldName => { | |
| 8125 | + const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' ); | |
| 8126 | + if ( ! optionsEl ) { | |
| 8127 | + return; | |
| 8128 | + } | |
| 8129 | + optionsEl.classList.remove( 'frm_hidden' ); | |
| 8130 | + }); | |
| 8131 | + }; | |
| 8132 | + | |
| 8133 | + const dropdownSelector = '.frm_name_layout_dropdown'; | |
| 8134 | + document.addEventListener( 'change', event => { | |
| 8135 | + if ( event.target.matches( dropdownSelector ) ) { | |
| 8136 | + onChangeLayout( event ); | |
| 8137 | + } | |
| 8138 | + }, false ); | |
| 8139 | + } | |
| 8140 | + | |
| 8141 | + function debounce( func, wait = 100 ) { | |
| 8142 | + let timeout; | |
| 8143 | + return function( ...args ) { | |
| 8144 | + clearTimeout( timeout ); | |
| 8145 | + timeout = setTimeout( | |
| 8146 | + () => func.apply( this, args ), | |
| 8147 | + wait | |
| 8148 | + ); | |
| 8149 | + }; | |
| 8150 | + } | |
| 8151 | + | |
| 8152 | + return { | |
| 8153 | + init: function() { | |
| 8154 | + s = {}; | |
| 8155 | + | |
| 8156 | + // Bootstrap dropdown button | |
| 8157 | + jQuery( '.wp-admin' ).on( 'click', function( e ) { | |
| 8158 | + var t = jQuery( e.target ); | |
| 8159 | + var $openDrop = jQuery( '.dropdown.open' ); | |
| 8160 | + if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) { | |
| 8161 | + $openDrop.removeClass( 'open' ); | |
| 8162 | + } | |
| 8163 | + }); | |
| 8164 | + jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox ); | |
| 8165 | + | |
| 8166 | + if ( typeof thisFormId === 'undefined' ) { | |
| 8167 | + thisFormId = jQuery( document.getElementById( 'form_id' ) ).val(); | |
| 8168 | + } | |
| 8169 | + | |
| 8170 | + if ( $newFields.length > 0 ) { | |
| 8171 | + // only load this on the form builder page | |
| 8172 | + frmAdminBuild.buildInit(); | |
| 8173 | + } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) { | |
| 8174 | + // only load on form settings page | |
| 8175 | + frmAdminBuild.settingsInit(); | |
| 8176 | + } else if ( document.getElementById( 'frm_styling_form' ) !== null ) { | |
| 8177 | + // load styling settings js | |
| 8178 | + frmAdminBuild.styleInit(); | |
| 8179 | + } else if ( document.getElementById( 'frm_custom_css_box' ) !== null ) { | |
| 8180 | + // load styling settings js | |
| 8181 | + frmAdminBuild.customCSSInit(); | |
| 8182 | + } else if ( document.getElementById( 'form_global_settings' ) !== null ) { | |
| 8183 | + // global settings page | |
| 8184 | + frmAdminBuild.globalSettingsInit(); | |
| 8185 | + } else if ( document.getElementById( 'frm_export_xml' ) !== null ) { | |
| 8186 | + // import/export page | |
| 8187 | + frmAdminBuild.exportInit(); | |
| 8188 | + } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) { | |
| 8189 | + // only load on views settings page | |
| 8190 | + frmAdminBuild.viewInit(); | |
| 8191 | + } else if ( document.getElementById( 'frm_inbox_page' ) !== null ) { | |
| 8192 | + // Inbox page | |
| 8193 | + frmAdminBuild.inboxInit(); | |
| 8194 | + } else if ( document.getElementById( 'frm-welcome' ) !== null ) { | |
| 8195 | + // Solution install page | |
| 8196 | + frmAdminBuild.solutionInit(); | |
| 8197 | + } else { | |
| 8198 | + // New form selection page | |
| 8199 | + initNewFormModal(); | |
| 8200 | + initSelectionAutocomplete(); | |
| 8201 | + | |
| 8202 | + jQuery( '[data-frmprint]' ).on( 'click', function() { | |
| 8203 | + window.print(); | |
| 8204 | + return false; | |
| 8205 | + }); | |
| 8206 | + } | |
| 8207 | + | |
| 8208 | + var $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); | |
| 8209 | + if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) { | |
| 8210 | + // only load on the form, form settings, and view settings pages | |
| 8211 | + frmAdminBuild.panelInit(); | |
| 8212 | + } | |
| 8213 | + | |
| 8214 | + loadTooltips(); | |
| 8215 | + initUpgradeModal(); | |
| 8216 | + | |
| 8217 | + // used on build, form settings, and view settings | |
| 8218 | + var $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) ); | |
| 8219 | + if ( $shortCodeDiv.length > 0 ) { | |
| 8220 | + jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() { | |
| 8221 | + if ( $shortCodeDiv.is( ':hidden' ) ) { | |
| 8222 | + $shortCodeDiv.slideDown( 'fast' ); | |
| 8223 | + this.style.display = 'none'; | |
| 8224 | + } | |
| 8225 | + return false; | |
| 8226 | + }); | |
| 8227 | + | |
| 8228 | + jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() { | |
| 8229 | + $shortCodeDiv.slideUp( 'fast' ); | |
| 8230 | + $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show(); | |
| 8231 | + return false; | |
| 8232 | + }); | |
| 8233 | + } | |
| 8234 | + | |
| 8235 | + // tabs | |
| 8236 | + jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab ); | |
| 8237 | + jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() { | |
| 8238 | + if ( ! this.classList.contains( 'frm_noallow' ) ) { | |
| 8239 | + clickTab( this ); | |
| 8240 | + return false; | |
| 8241 | + } | |
| 8242 | + }); | |
| 8243 | + clickTab( jQuery( '.starttab a' ), 'auto' ); | |
| 8244 | + | |
| 8245 | + // submit the search form with dropdown | |
| 8246 | + jQuery( '#frm-fid-search-menu a' ).on( 'click', function() { | |
| 8247 | + var val = this.id.replace( 'fid-', '' ); | |
| 8248 | + jQuery( 'select[name="fid"]' ).val( val ); | |
| 8249 | + triggerSubmit( document.getElementById( 'posts-filter' ) ); | |
| 8250 | + return false; | |
| 8251 | + }); | |
| 8252 | + | |
| 8253 | + jQuery( '.frm_select_box' ).on( 'click focus', function() { | |
| 8254 | + this.select(); | |
| 8255 | + }); | |
| 8256 | + | |
| 8257 | + jQuery( document ).on( 'input search change', '.frm-auto-search', searchContent ); | |
| 8258 | + jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation ); | |
| 8259 | + var autoSearch = jQuery( '.frm-auto-search' ); | |
| 8260 | + if ( autoSearch.val() !== '' ) { | |
| 8261 | + autoSearch.trigger( 'keyup' ); | |
| 8262 | + } | |
| 8263 | + | |
| 8264 | + // Initialize Formidable Connection. | |
| 8265 | + FrmFormsConnect.init(); | |
| 8266 | + | |
| 8267 | + jQuery( document ).on( 'click', '.frm-install-addon', installAddon ); | |
| 8268 | + jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon ); | |
| 8269 | + jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons ); | |
| 8270 | + | |
| 8271 | + // prevent annoying confirmation message from WordPress | |
| 8272 | + jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload ); | |
| 8273 | + }, | |
| 8274 | + | |
| 8275 | + buildInit: function() { | |
| 8276 | + var loadFieldId, $builderForm, builderArea; | |
| 8277 | + | |
| 8278 | + if ( jQuery( '.frm_field_loading' ).length ) { | |
| 8279 | + loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' ); | |
| 8280 | + loadFields( loadFieldId ); | |
| 8281 | + } | |
| 8282 | + | |
| 8283 | + setupSortable( 'ul.frm_sorting' ); | |
| 8284 | + | |
| 8285 | + jQuery( '.field_type_list > li:not(.frm_noallow)' ).draggable({ | |
| 8286 | + connectToSortable: '#frm-show-fields', | |
| 8287 | + helper: 'clone', | |
| 8288 | + revert: 'invalid', | |
| 8289 | + delay: 10, | |
| 8290 | + cancel: '.frm-dropdown-menu' | |
| 8291 | + }); | |
| 8292 | + 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(); | |
| 8293 | + | |
| 8294 | + jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild ); | |
| 8295 | + jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax ); | |
| 8296 | + | |
| 8297 | + jQuery( 'a.edit-form-status' ).on( 'click', slideDown ); | |
| 8298 | + jQuery( '.cancel-form-status' ).on( 'click', slideUp ); | |
| 8299 | + jQuery( '.save-form-status' ).on( 'click', function() { | |
| 8300 | + var newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val(); | |
| 8301 | + jQuery( 'input[name="new_status"]' ).val( newStatus ); | |
| 8302 | + jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus ); | |
| 8303 | + jQuery( '.cancel-form-status' ).trigger( 'click' ); | |
| 8304 | + return false; | |
| 8305 | + }); | |
| 8306 | + | |
| 8307 | + jQuery( '.frm_form_builder form' ).first().on( 'submit', function() { | |
| 8308 | + jQuery( '.inplace_field' ).trigger( 'blur' ); | |
| 8309 | + }); | |
| 8310 | + | |
| 8311 | + initiateMultiselect(); | |
| 8312 | + renumberPageBreaks(); | |
| 8313 | + | |
| 8314 | + $builderForm = jQuery( builderForm ); | |
| 8315 | + builderArea = document.getElementById( 'frm_form_editor_container' ); | |
| 8316 | + $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow ); | |
| 8317 | + $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow ); | |
| 8318 | + $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection ); | |
| 8319 | + $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues ); | |
| 8320 | + $builderForm.on( 'change', '.scale_maxnum, .scale_minnum', setScaleValues ); | |
| 8321 | + $builderForm.on( 'change', '.radio_maxnum', setStarValues ); | |
| 8322 | + $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues ); | |
| 8323 | + | |
| 8324 | + jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick ); | |
| 8325 | + $newFields.on( 'click', '.frm_clone_field', duplicateField ); | |
| 8326 | + $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser ); | |
| 8327 | + $builderForm.on( 'change', 'input.frm_format_opt', toggleInvalidMsg ); | |
| 8328 | + $builderForm.on( 'change click', '[data-changeme]', liveChanges ); | |
| 8329 | + $builderForm.on( 'click', 'input.frm_req_field', markRequired ); | |
| 8330 | + $builderForm.on( 'click', '.frm_mark_unique', markUnique ); | |
| 8331 | + | |
| 8332 | + $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons ); | |
| 8333 | + $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit ); | |
| 8334 | + $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit ); | |
| 8335 | + $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() { | |
| 8336 | + updateRepeatText( this, 'add' ); | |
| 8337 | + }); | |
| 8338 | + $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() { | |
| 8339 | + updateRepeatText( this, 'remove' ); | |
| 8340 | + }); | |
| 8341 | + $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields ); | |
| 8342 | + jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage ); | |
| 8343 | + jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection ); | |
| 8344 | + $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings ); | |
| 8345 | + | |
| 8346 | + $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues ); | |
| 8347 | + $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions ); | |
| 8348 | + $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption ); | |
| 8349 | + $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption ); | |
| 8350 | + $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay ); | |
| 8351 | + $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize ); | |
| 8352 | + $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect ); | |
| 8353 | + $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus ); | |
| 8354 | + $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus ); | |
| 8355 | + $newFields.on( 'click', '.frm_delete_field', clickDeleteField ); | |
| 8356 | + $newFields.on( 'click', '.frm_select_field', clickSelectField ); | |
| 8357 | + jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout ); | |
| 8358 | + jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick ); | |
| 8359 | + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick ); | |
| 8360 | + jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick ); | |
| 8361 | + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick ); | |
| 8362 | + jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick ); | |
| 8363 | + $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick ); | |
| 8364 | + jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick ); | |
| 8365 | + jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick ); | |
| 8366 | + $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick ); | |
| 8367 | + jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick ); | |
| 8368 | + jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick ); | |
| 8369 | + $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() { | |
| 8370 | + this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' ); | |
| 8371 | + jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings ); | |
| 8372 | + }); | |
| 8373 | + $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove ); | |
| 8374 | + $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow ); | |
| 8375 | + $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption ); | |
| 8376 | + $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio ); | |
| 8377 | + $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText ); | |
| 8378 | + $builderForm.on( 'click', '.frm_add_opt', addFieldOption ); | |
| 8379 | + $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange ); | |
| 8380 | + $builderForm.on( 'change', '.frm_image_id', resetOptOnChange ); | |
| 8381 | + $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel ); | |
| 8382 | + $builderForm.on( 'focusin', '.frm_classes', showBuilderModal ); | |
| 8383 | + | |
| 8384 | + $newFields.on( 'click', '.frm_primary_label', clickLabel ); | |
| 8385 | + $newFields.on( 'click', '.frm_description', clickDescription ); | |
| 8386 | + $newFields.on( 'click', 'li.ui-state-default', clickVis ); | |
| 8387 | + $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced ); | |
| 8388 | + $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax ); | |
| 8389 | + $builderForm.on( 'change', 'select.conf_field', addConf ); | |
| 8390 | + | |
| 8391 | + $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection ); | |
| 8392 | + | |
| 8393 | + $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal ); | |
| 8394 | + | |
| 8395 | + $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal ); | |
| 8396 | + jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue ); | |
| 8397 | + | |
| 8398 | + $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary ); | |
| 8399 | + $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg ); | |
| 8400 | + | |
| 8401 | + jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax ); | |
| 8402 | + 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 ); | |
| 8403 | + | |
| 8404 | + popAllProductFields(); | |
| 8405 | + | |
| 8406 | + jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType ); | |
| 8407 | + | |
| 8408 | + jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus ); | |
| 8409 | + jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur ); | |
| 8410 | + | |
| 8411 | + initBulkOptionsOverlay(); | |
| 8412 | + hideEmptyEle(); | |
| 8413 | + maybeDisableAddSummaryBtn(); | |
| 8414 | + maybeHideQuantityProductFieldOption(); | |
| 8415 | + handleNameFieldOnFormBuilder(); | |
| 8416 | + toggleSectionHolder(); | |
| 8417 | + }, | |
| 8418 | + | |
| 8419 | + settingsInit: function() { | |
| 8420 | + var formSettings, $loggedIn, $cookieExp, $editable, | |
| 8421 | + $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) ); | |
| 8422 | + //BCC, CC, and Reply To button functionality | |
| 8423 | + $formActions.on( 'click', '.frm_email_buttons', showEmailRow ); | |
| 8424 | + $formActions.on( 'click', '.frm_remove_field', hideEmailRow ); | |
| 8425 | + $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning ); | |
| 8426 | + $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow ); | |
| 8427 | + $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost ); | |
| 8428 | + $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent ); | |
| 8429 | + $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent ); | |
| 8430 | + $formActions.on( 'change', '.frm_post_type', switchPostType ); | |
| 8431 | + $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow ); | |
| 8432 | + $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow ); | |
| 8433 | + $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts ); | |
| 8434 | + $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction ); | |
| 8435 | + jQuery( 'select[data-toggleclass], input[data-toggleclass]' ).on( 'change', toggleFormOpts ); | |
| 8436 | + jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction ); | |
| 8437 | + jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups ); | |
| 8438 | + initiateMultiselect(); | |
| 8439 | + | |
| 8440 | + //set actions icons to inactive | |
| 8441 | + jQuery( 'ul.frm_actions_list li' ).each( function() { | |
| 8442 | + checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) ); | |
| 8443 | + | |
| 8444 | + // If the icon is a background image, don't add BG color. | |
| 8445 | + var icon = jQuery( this ).find( 'i' ); | |
| 8446 | + if ( icon.css( 'background-image' ) !== 'none' ) { | |
| 8447 | + icon.addClass( 'frm-inverse' ); | |
| 8448 | + } | |
| 8449 | + }); | |
| 8450 | + | |
| 8451 | + jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings ); | |
| 8452 | + | |
| 8453 | + formSettings = jQuery( '.frm_form_settings' ); | |
| 8454 | + formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow ); | |
| 8455 | + formSettings.on( 'blur', '.frm_email_blur', formatEmailSetting ); | |
| 8456 | + formSettings.on( 'click', '.frm_already_used', onlyOneActionMessage ); | |
| 8457 | + | |
| 8458 | + formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic ); | |
| 8459 | + formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic ); | |
| 8460 | + formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts ); | |
| 8461 | + | |
| 8462 | + // Close shortcode modal on click. | |
| 8463 | + formSettings.on( 'mouseup', '*:not(.frm-show-box)', function( e ) { | |
| 8464 | + e.stopPropagation(); | |
| 8465 | + if ( e.target.classList.contains( 'frm-show-box' ) ) { | |
| 8466 | + return; | |
| 8467 | + } | |
| 8468 | + var sidebar = document.getElementById( 'frm_adv_info' ), | |
| 8469 | + isChild = jQuery( e.target ).closest( '#frm_adv_info' ).length > 0; | |
| 8470 | + | |
| 8471 | + if ( sidebar.getAttribute( 'data-fills' ) === e.target.id && typeof e.target.id !== 'undefined' ) { | |
| 8472 | + return; | |
| 8473 | + } | |
| 8474 | + | |
| 8475 | + if ( sidebar !== null && ! isChild && sidebar.display !== 'none' ) { | |
| 8476 | + hideShortcodes( sidebar ); | |
| 8477 | + } | |
| 8478 | + }); | |
| 8479 | + | |
| 8480 | + //Warning when user selects "Do not store entries ..." | |
| 8481 | + jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() { | |
| 8482 | + if ( this.checked ) { | |
| 8483 | + if ( confirm( frm_admin_js.no_save_warning ) !== true ) { | |
| 8484 | + // Uncheck box if user hits "Cancel" | |
| 8485 | + jQuery( this ).attr( 'checked', false ); | |
| 8486 | + } | |
| 8487 | + } | |
| 8488 | + }); | |
| 8489 | + | |
| 8490 | + //Show/hide Messages header | |
| 8491 | + jQuery( '#editable, #edit_action, #save_draft, #success_action' ).on( 'change', function() { | |
| 8492 | + maybeShowFormMessages(); | |
| 8493 | + }); | |
| 8494 | + jQuery( 'select[name="options[success_action]"], select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt ); | |
| 8495 | + | |
| 8496 | + $loggedIn = document.getElementById( 'logged_in' ); | |
| 8497 | + jQuery( $loggedIn ).on( 'change', function() { | |
| 8498 | + if ( this.checked ) { | |
| 8499 | + visible( '.hide_logged_in' ); | |
| 8500 | + } else { | |
| 8501 | + invisible( '.hide_logged_in' ); | |
| 8502 | + } | |
| 8503 | + }); | |
| 8504 | + | |
| 8505 | + $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) ); | |
| 8506 | + jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() { | |
| 8507 | + if ( this.value === 'cookie' ) { | |
| 8508 | + $cookieExp.fadeIn( 'slow' ); | |
| 8509 | + } else { | |
| 8510 | + $cookieExp.fadeOut( 'slow' ); | |
| 8511 | + } | |
| 8512 | + }); | |
| 8513 | + | |
| 8514 | + var $singleEntry = document.getElementById( 'single_entry' ); | |
| 8515 | + jQuery( $singleEntry ).on( 'change', function() { | |
| 8516 | + if ( this.checked ) { | |
| 8517 | + visible( '.hide_single_entry' ); | |
| 8518 | + } else { | |
| 8519 | + invisible( '.hide_single_entry' ); | |
| 8520 | + } | |
| 8521 | + | |
| 8522 | + if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) { | |
| 8523 | + $cookieExp.fadeIn( 'slow' ); | |
| 8524 | + } else { | |
| 8525 | + $cookieExp.fadeOut( 'slow' ); | |
| 8526 | + } | |
| 8527 | + }); | |
| 8528 | + | |
| 8529 | + jQuery( '.hide_save_draft' ).hide(); | |
| 8530 | + | |
| 8531 | + var $saveDraft = jQuery( document.getElementById( 'save_draft' ) ); | |
| 8532 | + $saveDraft.on( 'change', function() { | |
| 8533 | + if ( this.checked ) { | |
| 8534 | + jQuery( '.hide_save_draft' ).fadeIn( 'slow' ); | |
| 8535 | + } else { | |
| 8536 | + jQuery( '.hide_save_draft' ).fadeOut( 'slow' ); | |
| 8537 | + } | |
| 8538 | + }); | |
| 8539 | + triggerChange( $saveDraft ); | |
| 8540 | + | |
| 8541 | + //If Allow editing is checked/unchecked | |
| 8542 | + $editable = document.getElementById( 'editable' ); | |
| 8543 | + jQuery( $editable ).on( 'change', function() { | |
| 8544 | + if ( this.checked ) { | |
| 8545 | + jQuery( '.hide_editable' ).fadeIn( 'slow' ); | |
| 8546 | + triggerChange( document.getElementById( 'edit_action' ) ); | |
| 8547 | + } else { | |
| 8548 | + jQuery( '.hide_editable' ).fadeOut( 'slow' ); | |
| 8549 | + jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box | |
| 8550 | + } | |
| 8551 | + }); | |
| 8552 | + | |
| 8553 | + //If File Protection is checked/unchecked | |
| 8554 | + jQuery( document ).on( 'change', '#protect_files', function() { | |
| 8555 | + if ( this.checked ) { | |
| 8556 | + jQuery( '.hide_protect_files' ).fadeIn( 'slow' ); | |
| 8557 | + } else { | |
| 8558 | + jQuery( '.hide_protect_files' ).fadeOut( 'slow' ); | |
| 8559 | + } | |
| 8560 | + }); | |
| 8561 | + | |
| 8562 | + jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues ); | |
| 8563 | + | |
| 8564 | + jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted ); | |
| 8565 | + jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated ); | |
| 8566 | + | |
| 8567 | + // Page Selection Autocomplete | |
| 8568 | + initSelectionAutocomplete(); | |
| 8569 | + }, | |
| 8570 | + | |
| 8571 | + panelInit: function() { | |
| 8572 | + var customPanel, settingsPage, viewPage, insertFieldsTab; | |
| 8573 | + | |
| 8574 | + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode ); | |
| 8575 | + jQuery( document ).on( 'change', '.frm_insert_val', function() { | |
| 8576 | + insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() ); | |
| 8577 | + jQuery( this ).val( '' ); | |
| 8578 | + }); | |
| 8579 | + | |
| 8580 | + jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder ); | |
| 8581 | + jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample ); | |
| 8582 | + | |
| 8583 | + showInputIcon(); | |
| 8584 | + jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) { | |
| 8585 | + /* This is here for add-ons to trigger */ | |
| 8586 | + showInputIcon( parentEle ); | |
| 8587 | + }); | |
| 8588 | + jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes ); | |
| 8589 | + | |
| 8590 | + settingsPage = document.getElementById( 'form_settings_page' ); | |
| 8591 | + viewPage = document.body.classList.contains( 'post-type-frm_display' ); | |
| 8592 | + insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' ); | |
| 8593 | + | |
| 8594 | + if ( settingsPage !== null || viewPage ) { | |
| 8595 | + jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) { | |
| 8596 | + var htmlTab; | |
| 8597 | + e.stopPropagation(); | |
| 8598 | + maybeShowModal( this ); | |
| 8599 | + | |
| 8600 | + if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) { | |
| 8601 | + if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) { | |
| 8602 | + // Don't trigger for fields inside of the modal. | |
| 8603 | + return; | |
| 8604 | + } | |
| 8605 | + | |
| 8606 | + if ( settingsPage !== null ) { | |
| 8607 | + /* form settings page */ | |
| 8608 | + htmlTab = jQuery( '#frm_html_tab' ); | |
| 8609 | + if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) { | |
| 8610 | + htmlTab.show(); | |
| 8611 | + htmlTab.siblings().hide(); | |
| 8612 | + jQuery( '#frm_html_tab a' ).trigger( 'click' ); | |
| 8613 | + toggleAllowedHTML( this, e.type ); | |
| 8614 | + } else { | |
| 8615 | + showElement( jQuery( '.frm-category-tabs li' ) ); | |
| 8616 | + insertFieldsTab.click(); | |
| 8617 | + htmlTab.hide(); | |
| 8618 | + htmlTab.siblings().show(); | |
| 8619 | + } | |
| 8620 | + } else if ( viewPage ) { | |
| 8621 | + // Run on view page. | |
| 8622 | + toggleAllowedShortcodes( this.id, e.type ); | |
| 8623 | + } | |
| 8624 | + } | |
| 8625 | + }); | |
| 8626 | + } | |
| 8627 | + | |
| 8628 | + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) { | |
| 8629 | + e.preventDefault(); | |
| 8630 | + }); | |
| 8631 | + | |
| 8632 | + customPanel = jQuery( '#frm_adv_info' ); | |
| 8633 | + customPanel.on( 'click', '.subsubsub a.frmids', function( e ) { | |
| 8634 | + toggleKeyID( 'frmids', e ); | |
| 8635 | + }); | |
| 8636 | + customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) { | |
| 8637 | + toggleKeyID( 'frmkeys', e ); | |
| 8638 | + }); | |
| 8639 | + }, | |
| 8640 | + | |
| 8641 | + viewInit: function() { | |
| 8642 | + var $addRemove, | |
| 8643 | + $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); | |
| 8644 | + $advInfo.before( '<div id="frm_position_ele"></div>' ); | |
| 8645 | + setupMenuOffset(); | |
| 8646 | + | |
| 8647 | + jQuery( document ).on( 'blur', '#param', checkDetailPageSlug ); | |
| 8648 | + jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames ); | |
| 8649 | + | |
| 8650 | + // Show loading indicator. | |
| 8651 | + jQuery( '#publish' ).on( 'mousedown', function() { | |
| 8652 | + fieldsUpdated = 0; | |
| 8653 | + this.classList.add( 'frm_loading_button' ); | |
| 8654 | + }); | |
| 8655 | + | |
| 8656 | + // move content tabs | |
| 8657 | + jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) ); | |
| 8658 | + | |
| 8659 | + // click content tabs | |
| 8660 | + jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab ); | |
| 8661 | + | |
| 8662 | + // click tabs after panel is replaced with ajax | |
| 8663 | + jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax ); | |
| 8664 | + | |
| 8665 | + initToggleShortcodes(); | |
| 8666 | + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ); | |
| 8667 | + | |
| 8668 | + jQuery( 'input[name="show_count"]' ).on( 'change', showCount ); | |
| 8669 | + | |
| 8670 | + jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected ); | |
| 8671 | + | |
| 8672 | + $addRemove = jQuery( '.frm_repeat_rows' ); | |
| 8673 | + $addRemove.on( 'click', '.frm_add_order_row', addOrderRow ); | |
| 8674 | + $addRemove.on( 'click', '.frm_add_where_row', addWhereRow ); | |
| 8675 | + $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions ); | |
| 8676 | + $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions ); | |
| 8677 | + | |
| 8678 | + setDefaultPostStatus(); | |
| 8679 | + }, | |
| 8680 | + | |
| 8681 | + inboxInit: function() { | |
| 8682 | + jQuery( '.frm_inbox_dismiss, footer .frm-button-secondary, footer .frm-button-primary' ).on( 'click', function( e ) { | |
| 8683 | + var message = this.parentNode.parentNode, | |
| 8684 | + key = message.getAttribute( 'data-message' ), | |
| 8685 | + href = this.getAttribute( 'href' ); | |
| 8686 | + | |
| 8687 | + if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) { | |
| 8688 | + return; | |
| 8689 | + } | |
| 8690 | + | |
| 8691 | + e.preventDefault(); | |
| 8692 | + | |
| 8693 | + data = { | |
| 8694 | + action: 'frm_inbox_dismiss', | |
| 8695 | + key: key, | |
| 8696 | + nonce: frmGlobal.nonce | |
| 8697 | + }; | |
| 8698 | + postAjax( data, function() { | |
| 8699 | + if ( href !== '#' ) { | |
| 8700 | + window.location = href; | |
| 8701 | + return true; | |
| 8702 | + } | |
| 8703 | + fadeOut( message, function() { | |
| 8704 | + message.parentNode.removeChild( message ); | |
| 8705 | + }); | |
| 8706 | + }); | |
| 8707 | + }); | |
| 8708 | + jQuery( '#frm-dismiss-inbox' ).on( 'click', function( e ) { | |
| 8709 | + data = { | |
| 8710 | + action: 'frm_inbox_dismiss', | |
| 8711 | + key: 'all', | |
| 8712 | + nonce: frmGlobal.nonce | |
| 8713 | + }; | |
| 8714 | + postAjax( data, function() { | |
| 8715 | + fadeOut( document.getElementById( 'frm_message_list' ), function() { | |
| 8716 | + document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' ); | |
| 8717 | + }); | |
| 8718 | + }); | |
| 8719 | + }); | |
| 8720 | + }, | |
| 8721 | + | |
| 8722 | + solutionInit: function() { | |
| 8723 | + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate ); | |
| 8724 | + }, | |
| 8725 | + | |
| 8726 | + styleInit: function() { | |
| 8727 | + collapseAllSections(); | |
| 8728 | + | |
| 8729 | + document.getElementById( 'frm_field_height' ).addEventListener( 'change', textSquishCheck ); | |
| 8730 | + document.getElementById( 'frm_field_font_size' ).addEventListener( 'change', textSquishCheck ); | |
| 8731 | + document.getElementById( 'frm_field_pad' ).addEventListener( 'change', textSquishCheck ); | |
| 8732 | + | |
| 8733 | + jQuery( 'input.hex' ).wpColorPicker({ | |
| 8734 | + change: function( event ) { | |
| 8735 | + var hexcolor = jQuery( this ).wpColorPicker( 'color' ); | |
| 8736 | + jQuery( event.target ).val( hexcolor ).trigger( 'change' ); | |
| 8737 | + } | |
| 8738 | + }); | |
| 8739 | + jQuery( '.wp-color-result-text' ).text( function( i, oldText ) { | |
| 8740 | + return oldText === 'Select Color' ? 'Select' : oldText; | |
| 8741 | + }); | |
| 8742 | + | |
| 8743 | + function changeStyling() { | |
| 8744 | + var locStr = jQuery( 'input[name^="frm_style_setting[post_content]"], select[name^="frm_style_setting[post_content]"], textarea[name^="frm_style_setting[post_content]"], input[name="style_name"]' ).serializeArray(); | |
| 8745 | + locStr = JSON.stringify( locStr ); | |
| 8746 | + jQuery.ajax({ | |
| 8747 | + type: 'POST', url: ajaxurl, | |
| 8748 | + data: { | |
| 8749 | + action: 'frm_change_styling', | |
| 8750 | + nonce: frmGlobal.nonce, | |
| 8751 | + frm_style_setting: locStr | |
| 8752 | + }, | |
| 8753 | + success: function( css ) { | |
| 8754 | + document.getElementById( 'this_css' ).innerHTML = css; | |
| 8755 | + } | |
| 8756 | + }); | |
| 8757 | + } | |
| 8758 | + | |
| 8759 | + // update styling on change | |
| 8760 | + jQuery( '#frm_styling_form .styling_settings' ).on( 'change', debounce( changeStyling, 100 ) ); | |
| 8761 | + | |
| 8762 | + // menu tabs | |
| 8763 | + jQuery( '#menu-settings-column' ).on( 'click', function( e ) { | |
| 8764 | + var panelId, wrapper, | |
| 8765 | + target = jQuery( e.target ); | |
| 8766 | + | |
| 8767 | + if ( e.target.className.indexOf( 'nav-tab-link' ) !== -1 ) { | |
| 8768 | + | |
| 8769 | + panelId = target.data( 'type' ); | |
| 8770 | + | |
| 8771 | + wrapper = target.parents( '.accordion-section-content' ).first(); | |
| 8772 | + | |
| 8773 | + | |
| 8774 | + jQuery( '.tabs-panel-active', wrapper ).removeClass( 'tabs-panel-active' ).addClass( 'tabs-panel-inactive' ); | |
| 8775 | + jQuery( '#' + panelId, wrapper ).removeClass( 'tabs-panel-inactive' ).addClass( 'tabs-panel-active' ); | |
| 8776 | + | |
| 8777 | + jQuery( '.tabs', wrapper ).removeClass( 'tabs' ); | |
| 8778 | + target.parent().addClass( 'tabs' ); | |
| 8779 | + | |
| 8780 | + // select the search bar | |
| 8781 | + jQuery( '.quick-search', wrapper ).trigger( 'focus' ); | |
| 8782 | + | |
| 8783 | + e.preventDefault(); | |
| 8784 | + } | |
| 8785 | + }); | |
| 8786 | + | |
| 8787 | + jQuery( '.multiselect-container.frm-dropdown-menu li a' ).on( 'click', function() { | |
| 8788 | + var radio = this.children[0].children[0]; | |
| 8789 | + var btnGrp = jQuery( this ).closest( '.btn-group' ); | |
| 8790 | + var btnId = btnGrp.attr( 'id' ); | |
| 8791 | + document.getElementById( btnId.replace( '_select', '' ) ).value = radio.value; | |
| 8792 | + btnGrp.children( 'button' ).html( radio.nextElementSibling.innerHTML + ' <b class="caret"></b>' ); | |
| 8793 | + | |
| 8794 | + // set active class | |
| 8795 | + btnGrp.find( 'li.active' ).removeClass( 'active' ); | |
| 8796 | + jQuery( this ).closest( 'li' ).addClass( 'active' ); | |
| 8797 | + }); | |
| 8798 | + | |
| 8799 | + jQuery( '#frm_confirm_modal' ).on( 'click', '[data-resetstyle]', function( e ) { | |
| 8800 | + var button = document.getElementById( 'frm_reset_style' ); | |
| 8801 | + | |
| 8802 | + button.classList.add( 'frm_loading_button' ); | |
| 8803 | + e.stopPropagation(); | |
| 8804 | + | |
| 8805 | + jQuery.ajax({ | |
| 8806 | + type: 'POST', url: ajaxurl, | |
| 8807 | + data: {action: 'frm_settings_reset', nonce: frmGlobal.nonce}, | |
| 8808 | + success: function( errObj ) { | |
| 8809 | + var key; | |
| 8810 | + errObj = errObj.replace( /^\s+|\s+$/g, '' ); | |
| 8811 | + if ( errObj.indexOf( '{' ) === 0 ) { | |
| 8812 | + errObj = JSON.parse( errObj ); | |
| 8813 | + } | |
| 8814 | + for ( key in errObj ) { | |
| 8815 | + jQuery( 'input[name$="[' + key + ']"], select[name$="[' + key + ']"]' ).val( errObj[key]); | |
| 8816 | + } | |
| 8817 | + jQuery( '#frm_submit_style, #frm_auto_width' ).prop( 'checked', false ); | |
| 8818 | + triggerChange( document.getElementById( 'frm_fieldset' ) ); | |
| 8819 | + button.classList.remove( 'frm_loading_button' ); | |
| 8820 | + } | |
| 8821 | + }); | |
| 8822 | + }); | |
| 8823 | + | |
| 8824 | + jQuery( '.frm_pro_form #datepicker_sample' ).datepicker({ changeMonth: true, changeYear: true }); | |
| 8825 | + | |
| 8826 | + jQuery( document.getElementById( 'frm_position' ) ).on( 'change', setPosClass ); | |
| 8827 | + | |
| 8828 | + jQuery( 'select[name$="[theme_selector]"]' ).on( 'change', function() { | |
| 8829 | + var themeVal = jQuery( this ).val(); | |
| 8830 | + var css = themeVal; | |
| 8831 | + if ( themeVal !== -1 ) { | |
| 8832 | + if ( themeVal === 'ui-lightness' && frm_admin_js.pro_url !== '' ) { | |
| 8833 | + css = frm_admin_js.pro_url + '/css/ui-lightness/jquery-ui.css'; | |
| 8834 | + jQuery( '.frm_date_color' ).show(); | |
| 8835 | + } else { | |
| 8836 | + css = frm_admin_js.jquery_ui_url + '/themes/' + themeVal + '/jquery-ui.css'; | |
| 8837 | + jQuery( '.frm_date_color' ).hide(); | |
| 8838 | + } | |
| 8839 | + } | |
| 8840 | + | |
| 8841 | + updateUICSS( css ); | |
| 8842 | + document.getElementById( 'frm_theme_css' ).value = themeVal; | |
| 8843 | + return false; | |
| 8844 | + }).trigger( 'change' ); | |
| 8845 | + }, | |
| 8846 | + | |
| 8847 | + customCSSInit: function() { | |
| 8848 | + /* deprecated since WP 4.9 */ | |
| 8849 | + var customCSS = document.getElementById( 'frm_custom_css_box' ); | |
| 8850 | + if ( customCSS !== null ) { | |
| 8851 | + CodeMirror.fromTextArea( customCSS, { | |
| 8852 | + lineNumbers: true | |
| 8853 | + }); | |
| 8854 | + } | |
| 8855 | + }, | |
| 8856 | + | |
| 8857 | + globalSettingsInit: function() { | |
| 8858 | + var licenseTab; | |
| 8859 | + | |
| 8860 | + jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow ); | |
| 8861 | + | |
| 8862 | + initiateMultiselect(); | |
| 8863 | + | |
| 8864 | + // activate addon licenses | |
| 8865 | + licenseTab = document.getElementById( 'licenses_settings' ); | |
| 8866 | + if ( licenseTab !== null ) { | |
| 8867 | + jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense ); | |
| 8868 | + } | |
| 8869 | + | |
| 8870 | + // Solution install page | |
| 8871 | + jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset ); | |
| 8872 | + | |
| 8873 | + jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) { | |
| 8874 | + event.preventDefault(); | |
| 8875 | + jQuery.post( ajaxurl, { | |
| 8876 | + action: 'frm_lite_settings_upgrade' | |
| 8877 | + }); | |
| 8878 | + jQuery( '.settings-lite-cta' ).remove(); | |
| 8879 | + }); | |
| 8880 | + }, | |
| 8881 | + | |
| 8882 | + exportInit: function() { | |
| 8883 | + jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration ); | |
| 8884 | + jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport ); | |
| 8885 | + jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError ); | |
| 8886 | + jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension ); | |
| 8887 | + jQuery( 'select[name="format"]' ).on( 'change', checkExportTypes ).trigger( 'change' ); | |
| 8888 | + jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport ); | |
| 8889 | + initiateMultiselect(); | |
| 8890 | + | |
| 8891 | + jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) { | |
| 8892 | + event.preventDefault(); | |
| 8893 | + jQuery.post( ajaxurl, { | |
| 8894 | + action: 'frm_dismiss_migrator', | |
| 8895 | + plugin: this.id, | |
| 8896 | + nonce: frmGlobal.nonce | |
| 8897 | + }); | |
| 8898 | + this.parentElement.remove(); | |
| 8899 | + }); | |
| 8900 | + }, | |
| 8901 | + | |
| 8902 | + updateOpts: function( fieldId, opts, modal ) { | |
| 8903 | + var separate = usingSeparateValues( fieldId ), | |
| 8904 | + action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options'; | |
| 8905 | + jQuery.ajax({ | |
| 8906 | + type: 'POST', | |
| 8907 | + url: ajaxurl, | |
| 8908 | + data: { | |
| 8909 | + action: action, | |
| 8910 | + field_id: fieldId, | |
| 8911 | + opts: opts, | |
| 8912 | + separate: separate, | |
| 8913 | + nonce: frmGlobal.nonce | |
| 8914 | + }, | |
| 8915 | + success: function( html ) { | |
| 8916 | + document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html; | |
| 8917 | + resetDisplayedOpts( fieldId ); | |
| 8918 | + | |
| 8919 | + if ( typeof modal !== 'undefined' ) { | |
| 8920 | + modal.dialog( 'close' ); | |
| 8921 | + document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' ); | |
| 8922 | + } | |
| 8923 | + } | |
| 8924 | + }); | |
| 8925 | + }, | |
| 8926 | + | |
| 8927 | + /* remove conditional logic if the field doesn't exist */ | |
| 8928 | + triggerRemoveLogic: function( fieldID, metaName ) { | |
| 8929 | + jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' ); | |
| 8930 | + }, | |
| 8931 | + | |
| 8932 | + downloadXML: function( controller, ids, isTemplate ) { | |
| 8933 | + var url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids; | |
| 8934 | + if ( isTemplate !== null ) { | |
| 8935 | + url = url + '&is_template=' + isTemplate; | |
| 8936 | + } | |
| 8937 | + location.href = url; | |
| 8938 | + } | |
| 8939 | + }; | |
| 8940 | +} | |
| 8941 | + | |
| 8942 | +frmAdminBuild = frmAdminBuildJS(); | |
| 8943 | + | |
| 8944 | +jQuery( document ).ready( function( $ ) { | |
| 8945 | + frmAdminBuild.init(); | |
| 8946 | +}); | |
| 8947 | + | |
| 8948 | +function frm_remove_tag( htmlTag ) { // eslint-disable-line camelcase | |
| 8949 | + console.warn( 'DEPRECATED: function frm_remove_tag in v2.0' ); | |
| 8950 | + jQuery( htmlTag ).remove(); | |
| 8951 | +} | |
| 8952 | + | |
| 8953 | +function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase | |
| 8954 | + if ( value == showIf ) { | |
| 8955 | + jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' ); | |
| 8956 | + } else { | |
| 8957 | + jQuery( classId + div ).fadeOut( 'slow' ); | |
| 8958 | + } | |
| 8959 | +} | |
| 8960 | + | |
| 8961 | +function frmCheckAll( checked, n ) { | |
| 8962 | + jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked ); | |
| 8963 | +} | |
| 8964 | + | |
| 8965 | +function frmCheckAllLevel( checked, n, level ) { | |
| 8966 | + var $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' ); | |
| 8967 | + $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked ); | |
| 8968 | +} | |
| 8969 | + | |
| 8970 | +function frm_add_logic_row( id, formId ) { // eslint-disable-line camelcase | |
| 8971 | + console.warn( 'DEPRECATED: function frm_add_logic_row in v2.0' ); | |
| 8972 | + jQuery.ajax({ | |
| 8973 | + type: 'POST', | |
| 8974 | + url: ajaxurl, | |
| 8975 | + data: { | |
| 8976 | + action: 'frm_add_logic_row', | |
| 8977 | + form_id: formId, | |
| 8978 | + field_id: id, | |
| 8979 | + meta_name: jQuery( '#frm_logic_row_' + id + ' > div' ).length, | |
| 8980 | + nonce: frmGlobal.nonce | |
| 8981 | + }, | |
| 8982 | + success: function( html ) { | |
| 8983 | + jQuery( '#frm_logic_row_' + id ).append( html ); | |
| 8984 | + } | |
| 8985 | + }); | |
| 8986 | + return false; | |
| 8987 | +} | |
| 8988 | + | |
| 8989 | +function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) { | |
| 8990 | + | |
| 8991 | + if ( fieldId ) { | |
| 8992 | + jQuery.ajax({ | |
| 8993 | + type: 'POST', url: ajaxurl, | |
| 8994 | + 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, | |
| 8995 | + success: function( msg ) { | |
| 8996 | + document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg; | |
| 8997 | + } | |
| 8998 | + }); | |
| 8999 | + } | |
| 9000 | +} | |
| 9001 | + | |
| 9002 | +function frmImportCsv( formID ) { | |
| 9003 | + var urlVars = ''; | |
| 9004 | + if ( typeof __FRMURLVARS !== 'undefined' ) { | |
| 9005 | + urlVars = __FRMURLVARS; | |
| 9006 | + } | |
| 9007 | + | |
| 9008 | + jQuery.ajax({ | |
| 9009 | + type: 'POST', url: ajaxurl, | |
| 9010 | + data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars, | |
| 9011 | + success: function( count ) { | |
| 9012 | + var max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' ); | |
| 9013 | + var imported = max - count; | |
| 9014 | + var percent = ( imported / max ) * 100; | |
| 9015 | + jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported ); | |
| 9016 | + | |
| 9017 | + if ( parseInt( count, 10 ) > 0 ) { | |
| 9018 | + jQuery( '.frm_csv_remaining' ).html( count ); | |
| 9019 | + frmImportCsv( formID ); | |
| 9020 | + } else { | |
| 9021 | + jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete ); | |
| 9022 | + setTimeout( function() { | |
| 9023 | + location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1'; | |
| 9024 | + }, 2000 ); | |
| 9025 | + } | |
| 9026 | + } | |
| 9027 | + }); | |
| 9028 | +} | |
| 9029 | + | |
| 9030 | +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill | |
| 9031 | +if ( ! String.prototype.trim ) { | |
| 9032 | + String.prototype.trim = function() { | |
| 9033 | + return this.replace( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '' ); | |
| 9034 | + }; | |
| 9035 | +} | |
| 9036 | +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill | |
| 9037 | +if ( ! String.prototype.startsWith ) { | |
| 9038 | + Object.defineProperty( String.prototype, 'startsWith', { | |
| 9039 | + value: function( search, pos ) { | |
| 9040 | + pos = ! pos || pos < 0 ? 0 : +pos; | |
| 9041 | + return this.substring( pos, pos + search.length ) === search; | |
| 9042 | + } | |
| 9043 | + }); | |
| 9044 | +} | |