芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/.trash/media/system/js/fields/joomla-field-color-slider-es5.min.js
!function(){"use strict";!function(t){var e=new RegExp(/^#([a-z0-9]{1,2})([a-z0-9]{1,2})([a-z0-9]{1,2})$/i),s=new RegExp(/^rgba?\(([0-9]+)[\D]+([0-9]+)[\D]+([0-9]+)(?:[\D]+([0-9](?:.\d+)?))?\)$/i),a=new RegExp(/^hsla?\(([0-9]+)[\D]+([0-9]+)[\D]+([0-9]+)[\D]+([0-9](?:.\d+)?)?\)$/i),i=new RegExp(/^(([0-1])|(0\\.[0-9]+)|([0-9]{1,2})|(100))$/),r=new RegExp(/^[0-9]{1,3}$/),h=function(){function t(t){var e=this;this.messageSpan=t.querySelector(".form-control-feedback"),this.mainInput=t.querySelector(".color-input"),this.input=t.querySelector("#slider-input"),this.sliders=t.querySelectorAll(".color-slider"),this.hueSlider=t.querySelector("#hue-slider"),this.saturationSlider=t.querySelector("#saturation-slider"),this.lightSlider=t.querySelector("#light-slider"),this.alphaSlider=t.querySelector("#alpha-slider"),this.color=t.dataset.color||"",this.default=t.dataset.default||"",this.format=this.input.dataset.format||"hex",this.saveFormat=this.mainInput.dataset.format||"hex",this.preview="true"===t.dataset.preview,this.setAlpha="hsla"===this.format||"rgba"===this.format,this.hue=360,this.saturation=1,this.light=1,this.alpha=1,this.defaultHsl=[this.hue,this.saturation,this.light,this.alpha],this.setInitValue(),this.setBackground(),this.preview?this.setInputPattern():this.input.classList.add("hidden"),this.mainInput.classList.add("hidden"),Array.prototype.forEach.call(this.sliders,(function(t){t.addEventListener("change",(function(){return e.updateValue(t)}))})),this.input.addEventListener("change",(function(){return e.changeInput(e.input)}))}var h=t.prototype;return h.updateValue=function(t){this.showError("");var e=this.getSliderValueAsHsl(t.value,t.dataset.type),s=this.hslToRgb(e);this.hue=e[0],this.saturation=e[1],this.light=e[2],this.alpha=e[3],this.input.style.border="2px solid "+this.getRgbString(s),this.setSliderValues(e,t.dataset.type),this.setInputValue(e),this.setBackground(t)},h.changeInput=function(t){var e=[this.hue,this.saturation,this.light,this.alpha];if(!t.value)return this.mainInput.value="",void this.showError("");if(this.checkValue(t.value)){switch(this.showError(""),this.format){case"hue":e[0]=t.value,this.hue=t.value;break;case"saturation":e[1]=t.value,this.saturation=t.value;break;case"light":e[2]=t.value,this.light=t.value;break;case"alpha":e[3]=t.value,this.alpha=t.value;break;default:e=this.getHsl(t.value)}this.setSliderValues(e),this.setInputValue(e,!0)}else this.showError("JFIELD_COLOR_ERROR_WRONG_FORMAT"),this.setInputValue(this.defaultHsl)},h.checkValue=function(t,h){switch(h||this.format){case"hue":return t<=360&&r.test(t);case"saturation":case"light":case"alpha":return i.test(t);case"hsl":case"hsla":return a.test(t);case"hex":return e.test(t);case"rgb":case"rgba":return s.test(t);default:return!1}},h.setInputPattern=function(){var t;switch(this.format){case"hue":t=r.source.slice(1,-1);break;case"saturation":case"light":case"alpha":t=i.source.slice(1,-1);break;case"hsl":case"hsla":t=a.source.slice(1,-1);break;case"rgb":t=s.source.slice(1,-1);break;case"hex":default:t=e.source.slice(1,-1)}this.input.setAttribute("pattern",t)},h.setBackground=function(t){var e=this;Array.prototype.forEach.call(this.sliders,(function(s){if(t!==s){var a=[],i=100;if(a.push(e.getSliderValueAsRgb(0,s.dataset.type)),"hue"===s.dataset.type){var r=Math.floor(18);i=360;for(var h=0;h<=360;h+=r)a.push(e.getSliderValueAsRgb(h,s.dataset.type))}else for(var l=0;l<=100;l+=10)a.push(e.getSliderValueAsRgb(l,s.dataset.type));a.push(e.getSliderValueAsRgb(i,s.dataset.type)),a=a.map((function(t){return e.getRgbString(t)})),s.style.background="linear-gradient(90deg, "+a.join(",")+")",s.style.webkitAppearance="none"}}))},h.setInitValue=function(){var t=window.getComputedStyle(this.input).getPropertyValue(this.default);if(this.default=t||this.default,""===this.color||void 0===this.color)return this.input.value="",void(this.mainInput.value="");var e=this.checkValue(this.color,this.saveFormat)?this.color:this.default;if(e){var s=[];/^[0-9]+$/.test(e)?(s=this.default&&this.getHsl(this.default),"hue"===this.format&&(s[0]=e),"saturation"===this.format&&(s[1]=e>1?e/100:e),"light"===this.format&&(s[2]=e>1?e/100:e),"alpha"===this.format&&(s[3]=e>1?e/100:e)):s=this.getHsl(e);var a=s;this.hue=a[0],this.saturation=a[1],this.light=a[2],this.alpha=s[4]||this.alpha,this.defaultHsl=this.default?this.getHsl(this.default):s,this.setSliderValues(s),this.setInputValue(s),this.input.style.border="2px solid "+this.getRgbString(this.hslToRgb(s))}else this.showError("JFIELD_COLOR_ERROR_NO_COLOUR")},h.showError=function(t){this.messageSpan.innerText=t?Joomla.Text._(t):""},h.getHsl=function(t){var i,r=[];if(Array.isArray(t))r=t;else if(e.test(t))r=this.hexToHsl(t);else if(s.test(t))r=this.rgbToHsl(t);else{if(!a.test(t))return this.showError("JFIELD_COLOR_ERROR_CONVERT_HSL"),this.defaultHsl;var h=t.match(a);r=[h[1],h[2],h[3],h[4]]}for(i=1;i
1?r[i]/100:r[i];return r},h.getSliderValueAsHsl=function(t,e){var s=this.hue,a=this.saturation,i=this.light,r=this.alpha;switch(e){case"alpha":r=t;break;case"saturation":a=t;break;case"light":i=t;break;case"hue":default:s=t}return i>1&&(i/=100),a>1&&(a/=100),r>1&&(r/=100),[s,a,i,r]},h.getSliderValueAsRgb=function(t,e){return this.hslToRgb(this.getSliderValueAsHsl(t,e))},h.setSliderValues=function(t,e){var s=t[0],a=t[1],i=t[2],r=t[3];this.hueSlider&&"hue"!==e&&(this.hueSlider.value=Math.round(s)),this.saturationSlider&&"saturation"!==e&&(this.saturationSlider.value=Math.round(100*a)),this.lightSlider&&"light"!==e&&(this.lightSlider.value=Math.round(100*i)),r&&this.alphaSlider&&"alpha"!==e&&(this.alphaSlider.value=Math.round(100*r))},h.setInputValue=function(t,e){var s=this,a=[this.mainInput];e||a.push(this.input),a.forEach((function(e){var a;switch(e.dataset.format){case"hsl":a=s.getHslString(t);break;case"hsla":a=s.getHslString(t,!0);break;case"rgb":a=s.getRgbString(s.hslToRgb(t));break;case"rgba":a=s.getRgbString(s.hslToRgb(t),!0);break;case"hex":a=s.rgbToHex(s.hslToRgb(t));break;case"alpha":a=Math.round(100*t[3]);break;case"saturation":a=Math.round(100*t[1]);break;case"light":a=Math.round(100*t[2]);break;case"hue":default:a=Math.round(t[0])}e.value=a}))},h.getRgbString=function(t,e){var s=t[0],a=t[1],i=t[2],r=t[3];return e||this.setAlpha?"rgba("+s+", "+a+", "+i+", "+(void 0===r?this.alpha:r)+")":"rgb("+s+", "+a+", "+i+")"},h.getHslString=function(t,e){var s=t[0],a=t[1],i=t[2],r=t[3],h=[s,a*=100,i*=100].map((function(t){return Math.round(t)}));return s=h[0],a=h[1],i=h[2],e||this.setAlpha?"hsla("+s+", "+a+"%, "+i+"%, "+(r=r||this.alpha)+")":"hsl("+s+", "+a+"%, "+i+"%)"},h.rgbToHex=function(t){var e=t[0].toString(16).toUpperCase(),s=t[1].toString(16).toUpperCase(),a=t[2].toString(16).toUpperCase();return"#"+(e=1===e.length?""+e+e:e)+(s=1===s.length?""+s+s:s)+(a=1===a.length?""+a+a:a)},h.rgbToHsl=function(t){var e=t;if("string"==typeof t){var a=t.match(s);e=[a[1],a[2],a[3],a[4]]}var i=e.map((function(t){return t>1?t/255:t})),r=i[0],h=i[1],l=i[2],u=Math.max(r,h,l),n=Math.min(r,h,l),o=(u+n)/2,c=u-n,d=0,g=0,p=e[3]||t[3]||this.alpha;if(u!==n)switch(g=0===u?u:1===n?n:(u-o)/Math.min(o,1-o),u){case r:d=60*(h-l)/c;break;case h:d=60*(2+(l-r)/c);break;case l:default:d=60*(4+(r-h)/c)}return[d=d<0?d+360:d,g,o,p=p>1?p/100:p]},h.hexToHsl=function(t){var s=t.match(e),a=s[1],i=s[2],r=s[3],h=[parseInt(a,16),parseInt(i,16),parseInt(r,16)];return this.rgbToHsl(h)},h.hslToRgb=function(t){var e=t[0],s=t[1],a=t[2],i=t[3],r=1,h=1,l=1,u=s>1?s/100:s,n=a>1?a/100:a,o=i>1?i/100:i;if(e<0||e>360||u<0||u>1||n<0||n>1)return this.showError("JFIELD_COLOR_ERROR_CONVERT_HSL"),this.hslToRgb(this.defaultHsl);var c=(1-Math.abs(2*n-1))*u,d=e/60,g=c*(1-Math.abs(d%2-1)),p=n-c/2;if(e>=0&&e<60)r=c,h=g,l=0;else if(e>=60&&e<120)r=g,h=c,l=0;else if(e>=120&&e<180)r=0,h=c,l=g;else if(e>=180&&e<240)r=0,h=g,l=c;else if(e>=240&&e<300)r=g,h=0,l=c;else{if(!(e>=300&&e<=360))return this.showError("JFIELD_COLOR_ERROR_CONVERT_HUE"),this.hslToRgb(this.defaultHsl);r=c,h=0,l=g}var f=[r,h,l].map((function(t){return Math.round(255*(t+p))}));return f.push(o),f},t}();t.addEventListener("DOMContentLoaded",(function(){var e=t.querySelectorAll(".color-slider-wrapper");e&&Array.prototype.forEach.call(e,(function(t){new h(t)}))}))}(document)}();