You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
7 months ago
|
var wpf={cachedFields:{},savedState:!1,initialSave:!0,orders:{fields:[],choices:{}},init:function(){wpf.bindUIActions(),wpf.initRadioGroupForCheckboxes(),jQuery(wpf.ready)},ready:function(){wpf.savedState=wpf.getFormState("#wpforms-builder-form"),wpf.setFieldOrders(),wpf.setChoicesOrders()},bindUIActions:function(){jQuery(document).on("wpformsFieldAdd",wpf.setFieldOrders),jQuery(document).on("wpformsFieldDelete",wpf.setFieldOrders),jQuery(document).on("wpformsFieldMove",wpf.setFieldOrders),jQuery(document).on("wpformsFieldAdd",wpf.setChoicesOrders),jQuery(document).on("wpformsFieldChoiceAdd",wpf.setChoicesOrders),jQuery(document).on("wpformsFieldChoiceDelete",wpf.setChoicesOrders),jQuery(document).on("wpformsFieldChoiceMove",wpf.setChoicesOrders),jQuery(document).on("wpformsFieldAdd",wpf.fieldUpdate),jQuery(document).on("wpformsFieldDelete",wpf.fieldUpdate),jQuery(document).on("wpformsFieldMove",wpf.fieldUpdate),jQuery(document).on("focusout",".wpforms-field-option-row-label input",wpf.fieldUpdate),jQuery(document).on("wpformsFieldChoiceAdd",wpf.fieldUpdate),jQuery(document).on("wpformsFieldChoiceDelete",wpf.fieldUpdate),jQuery(document).on("wpformsFieldChoiceMove",wpf.fieldUpdate),jQuery(document).on("wpformsFieldDynamicChoiceToggle",wpf.fieldUpdate),jQuery(document).on("focusout",".wpforms-field-option-row-choices input.label",wpf.fieldUpdate)},setFieldOrders:function(){wpf.orders.fields=[],jQuery(".wpforms-field-option").each(function(){wpf.orders.fields.push(jQuery(this).data("field-id"))})},setChoicesOrders:function(){wpf.orders.choices={},jQuery(".choices-list").each(function(){var e=jQuery(this).data("field-id");wpf.orders.choices["field_"+e]=[],jQuery(this).find("li").each(function(){wpf.orders.choices["field_"+e].push(jQuery(this).data("key"))})})},getChoicesOrder:function(e){var r=[];return jQuery("#wpforms-field-option-"+e).find(".choices-list li").each(function(){r.push(jQuery(this).data("key"))}),r},initMultipleSelectWithSearch:function(e){const r=jQuery(e.passedElement.element),t=jQuery(e.input.element);r.prop("multiple")&&(t.data("placeholder",t.attr("placeholder")),e.getValue(!0).length&&t.removeAttr("placeholder"),r.on("change",function(){e.getValue(!0).length?t.removeAttr("placeholder"):t.attr("placeholder",t.data("placeholder"))}))},fieldUpdate:function(){var e=wpf.getFields();jQuery(document).trigger("wpformsFieldUpdate",[e]),wpf.debug("fieldUpdate triggered")},getFields:function(e,r){if((r=r||!1)&&!jQuery.isEmptyObject(wpf.cachedFields)){var t=jQuery.extend({},wpf.cachedFields);wpf.debug("getFields triggered (cached)")}else{var i=["captcha","content","divider","entry-preview","html","internal-information","layout","pagebreak"];if(!(t=wpf.formObject("#wpforms-field-options").fields))return!1;for(n in t)(!t[n].type||-1<jQuery.inArray(t[n].type,i))&&delete t[n];wpf.cachedFields=jQuery.extend({},t),wpf.debug("getFields triggered")}if(e&&e.constructor===Array)for(var n in t)-1===jQuery.inArray(t[n].type,e)&&delete t[n];return t},getField:function(e){e=wpf.formObject("#wpforms-field-option-"+e);return e.fields[Object.keys(e.fields)[0]]},fieldOptionLoading:function(e,r){var e=jQuery(e),t=e.find("label");(r=void 0!==r)?(t.find(".wpforms-loading-spinner").remove(),t.find(".wpforms-help-tooltip").show(),e.find("input,select,textarea").prop("disabled",!1)):(t.append('<i class="wpforms-loading-spinner wpforms-loading-inline"></i>'),t.find(".wpforms-help-tooltip").hide(),e.find("input,select,textarea").prop("disabled",!0))},getFormState:function(e){return jQuery(e).serialize()},removeArrayItem:function(e,r){for(var t=0,i=0;i<e.length;i++)e[i]===r&&(e.splice(i,1),t++,i--);return t},sanitizeString:function(e){return"string"==typeof e||e instanceof String?e.trim():e},updateQueryString:function(e,r,t){t=t||window.location.href;var i,n=new RegExp("([?&])"+e+"=.*?(&|#|$)(.*)","gi");return n.test(t)?null!=r?t.replace(n,"$1"+e+"="+r+"$2$3"):(t=(i=t.split("#"))[0].replace(n,"$1$3").replace(/(&|\?)$/,""),void 0!==i[1]&&null!==i[1]&&(t+="#"+i[1]),t):(null!=r&&(n=-1!==t.indexOf("?")?"&":"?",t=(i=t.split("#"))[0]+n+e+"="+r,v
|