Files
conservatorio-tomadini/media/plg_system_nrframework/js/tffieldsvaluesapplier.js
2024-12-31 11:07:09 +01:00

3 lines
2.6 KiB
JavaScript

var TF_Fields_Values_Applier=function(){function e(e,t){this.data=e,this.item=t,this.breakpoints=["desktop","tablet","mobile"],this.dimensions=["top","right","bottom","left"],this.border_radius_dimensions=["top_left","top_right","bottom_right","bottom_left"]}var t=e.prototype;return t.applyItemData=function(){this.data[this.item]&&(this.data=this.data[this.item],this.applyData())},t.applyData=function(){for(var e in this.data){var t=this.data[e];e.startsWith("[")||e.endsWith("]")||(e="["+e+"]"),t.responsive||t.isResponsive?t.dimensions?this.setDimensionsResponsiveValue(e,t):this.setResponsiveValue(e,t):this.setValue(e,t.type,t.value)}},t.setDimensionsResponsiveValue=function(e,t){var i=t.type,s=t.value,n=t.border_radius||!1,o=n?this.border_radius_dimensions:this.dimensions;if(null!==s&&"object"==typeof s)for(breakpoint in s){if(null!==s[breakpoint]&&"object"!=typeof s[breakpoint]){var a=s[breakpoint];if(s[breakpoint]={},n)for(index in this.border_radius_dimensions)s[breakpoint][this.border_radius_dimensions[index]]=a;else for(index in this.dimensions)s[breakpoint][this.dimensions[index]]=a}for(dimension in s[breakpoint]){var r=e+"["+breakpoint+"]["+dimension+"]";this.setValue(r,i,s[breakpoint][dimension])}}else for(breakpoint in this.breakpoints)for(dimension in o){var p=e+"["+this.breakpoints[breakpoint]+"]["+o[dimension]+"]";this.setValue(p,i,s)}},t.setResponsiveValue=function(e,t){var i=t.type,s=t.value,n="";if(t.isResponsive&&(n+="[value]"),null!==s&&"object"==typeof s)for(breakpoint in s){var o=e+"["+breakpoint+"]"+n;this.setValue(o,i,s[breakpoint])}else for(breakpoint in this.breakpoints){var a=e+"["+this.breakpoints[breakpoint]+"]"+n;this.setValue(a,i,s)}},t.setValue=function(e,t,i){switch(t){case"text":case"number":case"color":var s=document.querySelector('input[type="'+t+'"][name$="'+e+'"]');s.value=i,s.closest(".nr-responsive-control--item")&&s.dispatchEvent(new CustomEvent("input",{bubbles:!0})),s.parentElement&&s.parentElement.classList.contains("minicolors")&&jQuery(s).minicolors&&jQuery(s).minicolors("value",i);break;case"nrtoggle":s=document.querySelector('input[type="checkbox"][name$="'+e+'"]');s.checked=i,s.dispatchEvent(new CustomEvent("change",{bubbles:!0}));break;case"radio":s=document.querySelector('input[type="radio"][name$="'+e+'"][value="'+i+'"]');s.checked=!0,s.dispatchEvent(new CustomEvent("change",{bubbles:!0}));break;case"list":s=document.querySelector('select[name$="'+e+'"]');s.value=i,!Joomla.Modal&&s.classList.contains("hasChosen")&&(jQuery(s).chosen("destroy"),jQuery(s).chosen()),s.dispatchEvent(new CustomEvent("change",{bubbles:!0}))}},e}();