1 line
2.1 KiB
JavaScript
1 line
2.1 KiB
JavaScript
|
|
var GravityFlowGenericMap=function(e){var o=this;return o.options=e,o.UI=jQuery("#gaddon-setting-row-"+o.options.fieldName),o.init=function(){o.bindEvents(),o.setupData(),o.setupRepeater()},o.bindEvents=function(){o.UI.on("change",'select[name="_gaddon_setting_'+o.options.keyFieldName+'"]',function(){var e=jQuery(this),t=e.next(".custom-key-container");"gf_custom"==e.val()&&e.fadeOut(function(){t.fadeIn().focus()})}),o.UI.on("change",'select[name="_gaddon_setting_'+o.options.valueFieldName+'"]',function(){var e=jQuery(this),t=e.next(".custom-value-container");"gf_custom"==e.val()&&e.fadeOut(function(){t.fadeIn().focus()})}),o.UI.on("click","a.custom-key-reset",function(e){e.preventDefault();var t=jQuery(this).parents(".custom-key-container"),n=t.prev("select.key");t.fadeOut(function(){t.find("input").val("").change(),n.fadeIn().focus().val("")})}),o.UI.on("click","a.custom-value-reset",function(e){e.preventDefault();var t=jQuery(this).parents(".custom-value-container"),n=t.prev("select.value");t.fadeOut(function(){t.find("input").val("").change(),n.fadeIn().focus().val("")})}),o.UI.closest("form").on("submit",function(e){jQuery('[name^="_gaddon_setting_'+o.options.fieldName+'_"]').each(function(e){jQuery(this).removeAttr("name")})})},o.setupData=function(){o.data=jQuery.parseJSON(jQuery("#"+o.options.fieldId).val()),o.data||(o.data=[{key:"",value:"",custom_key:"",custom_value:""}])},o.setupRepeater=function(){var e;e=0<o.options.limit?o.options.limit:0,o.UI.find("tbody.repeater").repeater({limit:e,items:o.data,addButtonMarkup:'<img src="'+o.options.baseURL+'/images/add.png" style="cursor:pointer;" />',removeButtonMarkup:'<img src="'+o.options.baseURL+'/images/remove.png" style="cursor:pointer;" />',callbacks:{add:function(e,t,n){var a=t.find('select[name="_gaddon_setting_'+o.options.keyFieldName+'"]');!n.custom_key&&0<a.length?t.find(".custom-key-container").hide():t.find(".key").hide();var i=t.find('select[name="_gaddon_setting_'+o.options.valueFieldName+'"]');!n.custom_value&&0<i.length?t.find(".custom-value-container").hide():t.find(".value").hide()},save:function(e,t){jQuery("#"+o.options.fieldId).val(jQuery.toJSON(t))}}})},o.init()};
|