policybot/fassets/rs-plugin/js/tp-color-picker.min.js

7 lines
51 KiB
JavaScript
Raw Permalink Normal View History

2021-11-30 10:56:55 +00:00
/**************************************************************************
* tp-color-picker.js - Color Picker Plugin for Revolution Slider
* @version: 1.0.4 (7.9.2017)
* @author ThemePunch
**************************************************************************/
window.RevColor={defaultValue:"#ffffff",isColor:/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i,get:function(e){return e?RevColor.process(e,!0)[0]:"transparent"},parse:function(e,r,a){e=RevColor.process(e,!0);var t=[];return t[0]=r?r+": "+e[0]+";":e[0],a&&(t[1]=e[1]),t},convert:function(e,r){if(!e||"string"!=typeof e)return RevColor.defaultValue;if("transparent"===e)return e;if(-1!==e.search(/\[\{/)||-1!==e.search("gradient"))return RevColor.process(e,!0)[0];if(void 0===r||isNaN(r))return RevColor.process(e,!0)[0];if((r=parseFloat(r))<=1&&(r*=100),0===(r=Math.max(Math.min(parseInt(r,10),100),0)))return"transparent";try{return-1!==e.search("#")||e.length<8?(RevColor.isColor.test(e)||(e=e.replace(/[^A-Za-z0-9#]/g,"")),RevColor.processRgba(RevColor.sanitizeHex(e),r)):(e=RevColor.rgbValues(e,3),RevColor.rgbaString(e[0],e[1],e[2],.01*r))}catch(e){return RevColor.defaultValue}},process:function(e,r){if("string"!=typeof e)return r&&(e=RevColor.sanitizeGradient(e)),[RevColor.processGradient(e),"gradient",e];if("transparent"===e.trim())return["transparent","transparent"];if(-1===e.search(/\[\{/))return-1!==e.search("#")?[RevColor.sanitizeHex(e),"hex"]:-1!==e.search("rgba")?[e.replace(/\s/g,"").replace(/false/g,"1"),"rgba"]:-1!==e.search("rgb")?[e.replace(/\s/g,""),"rgb"]:RevColor.isColor.test(e)?[e,"hex"]:["transparent","transparent",!0];try{return e=JSON.parse(e.replace(/\&/g,'"')),r&&(e=RevColor.sanitizeGradient(e)),[RevColor.processGradient(e),"gradient",e]}catch(e){return console.log("RevColor.process() failed to parse JSON string"),["linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(0, 0, 0, 1) 100%)","gradient",{type:"linear",angle:"0",colors:[{r:"255",g:"255",b:"255",a:"1",position:"0",align:"bottom"},{r:"0",g:"0",b:"0",a:"1",position:"100",align:"bottom"}]}]}},transparentRgba:function(e,r){return!(!r&&"rgba"!==RevColor.process(e)[1])&&"0"===RevColor.rgbValues(e,4)[3]},rgbValues:function(e,r){3===(e=e.substring(e.indexOf("(")+1,e.lastIndexOf(")")).split(",")).length&&4===r&&(e[3]="1");for(var a=0;a<r;a++)e[a]=e[a].trim();return e},rgbaString:function(e,r,a,t){return"rgba("+e+", "+r+", "+a+", "+t+")"},rgbToHex:function(e){var r=RevColor.rgbValues(e,3);return RevColor.getRgbToHex(r[0],r[1],r[2])},rgbaToHex:function(e){var r=RevColor.rgbValues(e,4);return[RevColor.getRgbToHex(r[0],r[1],r[2]),r[3]]},getOpacity:function(e){return parseInt(100*RevColor.rgbValues(e,4)[3],10)+"%"},getRgbToHex:function(e,r,a){return"#"+("0"+parseInt(e).toString(16)).slice(-2)+("0"+parseInt(r).toString(16)).slice(-2)+("0"+parseInt(a).toString(16)).slice(-2)},joinToRgba:function(e){return e=e.split("||"),RevColor.convert(e[0],e[1])},processRgba:function(e,r){e=e.replace("#","");var a=void 0!==r,t=(a?"rgba":"rgb")+"("+parseInt(e.substring(0,2),16)+", "+parseInt(e.substring(2,4),16)+", "+parseInt(e.substring(4,6),16);return t+=a?", "+(.01*parseInt(r,10)).toFixed(2).replace(/\.?0*$/,"")+")":")"},processGradient:function(e){for(var r,a=e.type,t=a+"-gradient(",i="linear"===a?e.angle+"deg, ":"ellipse at center, ",o=e.colors,c=o.length,n="",s=0;s<c;s++)s>0&&(n+=", "),n+="rgba("+(r=o[s]).r+", "+r.g+", "+r.b+", "+r.a+") "+r.position+"%";return t+i+n+")"},sanitizeHex:function(e){if(3===(e=e.replace("#","").trim()).length){var r=e.charAt(0),a=e.charAt(1),t=e.charAt(2);e=r+r+a+a+t+t}return"#"+e},sanitizeGradient:function(e){for(var r,a=e.colors,t=a.length,i=[],o=0;o<t;o++){var c=a[o];delete c.align,r?JSON.stringify(c)!==JSON.stringify(r)&&(i[i.length]=c):i[i.length]=c,r=c}return e.colors=i,e}},function(e){function r(e,r){var a=(e=e.split("("))[0];e.shift();var t=e.join("(").split(",");return t.shift(),r=void 0!==r?r+"deg,":"ellipse at center,",a+"("+r+t.join(",")}function a(e){return r(e.replace("radial-","linear-"),"90")}function t(){this.innerHTML=rr[c(this,"data-text")]}function i(){this.setAttribute("placeholder",rr[c(this,"data-placeholder")])}function o(){this.setAttribute("data-message",rr[c(this,"data-alert")])}function c(e,r){return e.getAttribute(r)||""}function n(r){r||(r={}),"string"==typeof r&&(r=JSON.parse(r.replace(/\&/g,'"'))),rr=e.extend({},Or,r),Te=r