📄 colorpicker.js
字号:
}
}
},
_vC:function(profile){
var pro=profile.properties,
v=pro.$UIvalue,
d=v==profile.$tempValue;
profile.getSubNode('SET').css('display',d?'none':'block');
profile.getSubNode('CAPTION').css('color',d?'#000':'#ff0000');
},
_prepareData:function(profile){
var data=arguments.callee.upper.call(this, profile);
var nodisplay='display:none';
data.displayBar= data.displayBar?'':nodisplay;
data.closeDisplay = data.closeBtn?'':nodisplay;
data._width = data.advance?'410':'210';
data.advDispay = data.advance?'':'display:none;';
return data;
},
EventHandlers:{
beforeClose:function(profile, src){}
},
RenderTrigger:function(){
this.$onValueSet=this.$onValueUpdated=function(v){
this.box._setClrName(this,v);
};
},
_setClrName:function(profile,v){
var p=profile,
k='color.LIST.',
vv=linb.getRes(k+v);
if(vv==v)
p.$clrN2 = p.$clrN = '#'+v;
else{
p.$clrN = vv;
p.$clrN2 = linb.wrapRes(k+v);
}
},
_slist:"FFFFFF,FFFFF0,FFFFE0,FFFF00,FFFAFA,FFFAF0,FFFACD,FFF8DC,FFF5EE,FFF0F5,FFEFD5,FFEBCD,FFE4E1,FFE4C4,FFE4B5,FFDEAD,FFDAB9,FFD700,FFC0CB,FFB6C1,FFA500,FFA07A,FF8C00,FF7F50,FF69B4,FF6347,FF4500,FF1493,FF00FF,FF00FF,FF0000,FDF5E6,FAFAD2,FAF0E6,FAEBD7,FA8072,F8F8FF,F5FFFA,F5F5F5,F5DEB3,F4A460,F0FFFF,F0FFF0,F0F8FF,F0E68C,F08080,EEE8AA,EE82EE,E9967A,E6E6FA,E1FFFF,DEB887,DDA0DD,DCDCDC,DC143C,DB7093,DAA520,DA70D6,D8BFD8,D3D3D3,D2B48C,D2691E,CD853F,CD5C5C,C71585,C0C0C0,BDB76B,BC8F8F,BA55D3,B22222,B0E0E6,B0C4DE,AFEEEE,ADFF2F,ADD8E6,A9A9A9,A52A2A,A0522D,9932CC,98FB98,9400D3,9370DB,90EE90,8FBC8F,8B4513,8B008B,8B0000,8A2BE2,87CEFA,87CEEB,808080,808000,800080,800000,7FFFAA,7FFF00,7CFC00,7B68EE,778899,708090,6B8E23,6A5ACD,696969,6495ED,5F9EA0,556B2F,4B0082,48D1CC,483D8B,4682B4,4169E1,40E0D0,3CB371,32CD32,2F4F4F,2E8B57,228B22,20B2AA,1E90FF,191970,00FFFF,00FFFF,00FF7F,00FF00,00FA9A,00CED1,00BFFF,008B8B,008080,008000,006400,0000FF,0000CD,00008B,000080,000000".split(','),
_C16:"0123456789ABCDEF",
//for drag rgb span
_dd1:function(profile, e, src, hsv){
var p=profile.properties,
cls=profile.box,
f=function(){var rgb = cls.hex2rgb(profile.$tempValue||p.$UIvalue); return hsv?cls.rgb2hsv(rgb):rgb;};
linb([src]).css('background','red').startDrag(e, {
dragType:'blank',
targetReposition:false,
widthIncrement:2,
dragCursor:true
});
profile.$temp=0;
profile.$start = f();
profile.$temp2 = f();
},
_dd2:function(profile, e, src, i, type){
var count,
off = linb.DragDrop.getProfile().offset,
p=profile.properties,
old=profile.$temp2,
cls=profile.box,
rate = type=='hsv1'?361:type=='hsv2'?101:256,
v;
count = (type=='hsv2'?parseInt(profile.$start[i]*100):parseInt(profile.$start[i]))+parseInt(off.x/2);
count=(count%rate+rate)%rate;
if(profile.$temp!=count){
old[i]=profile.$temp = type=='hsv2'?count/100:count;
v = (type=='hsv1'||type=='hsv2')?cls.hsv2rgb(old):old;
v=cls.rgb2hex(v);
cls._setTempUI(profile,v);
linb([src]).text(type=='hex'?cls._toFF(count):count);
}
},
_dd3:function(profile, e, src, i, hsv){
if(profile.$start[i] !== profile.$temp){
var p=profile.properties,
cls=profile.box,
old=profile.$start,
v;
old[i]=profile.$temp;
v=hsv?cls.hsv2rgb(old):old;
v=cls.rgb2hex(v);
//set the cur hex value of hsv for preventing update adv UI again
if(hsv)profile.$hexinhsv=v;
profile.boxing()._setCtrlValue(profile.$tempValue=v,false);
delete profile.$hexinhsv;
profile.box._vC(profile);
}
linb([src]).css('background','');
profile.$temp=profile.$start=0;
},
//set temp UI
_setTempUI:function(p,v){
var cls=this,
rgb=cls.hex2rgb(v),
b=p.boxing(),
ex=b.getSubNode('EXAMI'),
hsv=cls.rgb2hsv(rgb),
vv=linb.getRes('color.LIST.'+v);
ex.css({backgroundColor:'#'+v, color:hsv[2]>0.6?'#000':'#FFF'});
ex.text(p.show_color=vv==v?'#'+v:vv);
},
//reset example block
_updateDftTip:function(p){
var cls=p.box,
ex=p.boxing().getSubNode('EXAMI');
ex.css({backgroundColor:'#'+p.$hex.join(''), color:p.$hsv[2]>0.6?'#000':'#FFF'});
ex.html(p.$clrN2||'',false);
},
_to3:function(s){
if(!s)s="FFFFFF";
return [s.substr(0, 2), s.substr(2, 2), s.substr(4, 2)];
},
//0...255 to 00...FF
_toFF: function(n) {
var C16=this._C16;
n = parseInt(n)||0;
n = (n>255||n<0)?0:n;
return C16.charAt((n-n%16)/16) + C16.charAt(n%16);
},
// 00...FF to 0...255
_to255: function(str) {
var C16=this._C16, s=str.split('');
return C16.indexOf(s[0].toUpperCase())*16 + C16.indexOf(s[1].toUpperCase());
},
_webSafe:function(r, g, b){
//safe divisor is 51, smart divisor is 17
var me=arguments.callee,f=me.f||(me.f=function(n){
return parseInt(n/51)*51;
});
if(typeof r=='object'){
g=r[1];b=r[2];r=r[0];
}
return [f(r),f(g),f(b)];
},
_updateMarks:function(profile, hex, forcePos, hsv0){
var cls=this,
rgb=cls.hex2rgb(hex),
hsv=cls.rgb2hsv(rgb),
angle=(hsv[0]/360)*6.28,
clr=profile.getSubNode('ADVCLR');
if(forcePos){
var m1=profile.getSubNode('ADVMARK1'),
m2=profile.getSubNode('ADVMARK2');
m1.cssPos({
left: Math.round(Math.sin(angle)*cls._radius+cls._bigRadius),
top: Math.round(-Math.cos(angle)*cls._radius+cls._bigRadius)
});
m2.cssPos({
left: Math.round(cls._square*(hsv[1]-0.5)+cls._bigRadius),
top: Math.round(cls._square*(0.5-hsv[2])+cls._bigRadius)
});
}
if(hsv0 !== undefined)
clr.css('backgroundColor', '#'+cls.rgb2hex(cls.hsv2rgb([hsv0, 1, 1])));
cls._setTempUI(profile, hex);
},
//flag:change h
_updateClrByPos:function(profile, e, flag){
var cls=this,
mPos=linb.Event.getPos(e),
pos=profile.$tpos,
left=mPos.left-pos.left,
top=mPos.top-pos.top,
angle,m1,m2,
h,s,v,hsv,rgb,hex;
;
if(flag){
m1=profile.getSubNode('ADVMARK1');
angle=Math.atan2(left, -top);
m1.cssPos({
left: Math.round(Math.sin(angle)*cls._radius+cls._bigRadius),
top: Math.round(-Math.cos(angle)*cls._radius+cls._bigRadius)
});
h=Math.floor((angle/6.28)*360);
if(h<0)h +=360;
hsv=[h, profile.$hsv[1], profile.$hsv[2]];
rgb = cls.hsv2rgb(hsv);
hex = cls.rgb2hex(rgb);
cls._updateMarks(profile, profile.$t_hex=hex, false, h);
}else{
m2=profile.getSubNode('ADVMARK2');
s=Math.max(0, Math.min(1, (left/cls._square) + 0.5));
v=Math.max(0, Math.min(1, 0.5 - (top/cls._square)));
m2.cssPos({
left: Math.round(cls._square*(s-0.5)+cls._bigRadius),
top: Math.round(cls._square*(0.5-v)+cls._bigRadius)
});
hsv=[profile.$hsv[0], s, v];
rgb = cls.hsv2rgb(hsv);
hex = cls.rgb2hex(rgb);
cls._updateMarks(profile, profile.$t_hex=hex);
}
},
_updateValueByPos:function(profile, e){
//set the cur hex value of adv for preventing update adv UI again
profile.$hexinadv=profile.$t_hex;
profile.boxing()._setCtrlValue(profile.$tempValue=profile.$t_hex,false);
delete profile.$hexinadv;
profile.box._vC(profile);
},
_prepareAdv:function(profile,e){
var cls=this,
pos=profile.getSubNode('ADVWHEEL').offset();
profile.$tpos= { left:pos.left+cls._bigRadius, top:pos.top+cls._bigRadius };
},
_ensureValue:function(profile,v){
var ns=this,me=arguments.callee,map=me.map||(me.map=(function(){
var h={};
_.arr.each(ns._C16.split(''),function(o,i){
h[o]=1;
});
return h;
}())),
reg=me._r||(me._r=/rgb\(([^)]*)\)/);
if(!v || typeof v !='string')return 'FFFFFF';
if(reg.test(v)){
v=v.replace(reg,'$1');
v=v.split(',');
v[0]=parseInt(v[0])||0;
v[1]=parseInt(v[1])||0;
v[2]=parseInt(v[2])||0;
v=ns.rgb2hex(v);
}
if(v.charAt(0)=='#')v=v.substr(1,v.length);
var a='',k;
for(var i=0;i<6;i++){
k=v.charAt(i).toUpperCase();
a += (map[k]?k:'F');
}
return a;
},
//HSV (h[0-360], s[0-1]), v[0-1] to RGB [255,255,255]
hsv2rgb: function(h, s, v) {
if(h instanceof Array) {
s=h[1]; v=h[2]; h=h[0];
}
var me=arguments.callee, f = me.f ||
(me.f=function(n) {
return Math.min(255, Math.round(n*256));
}),
r, g, b, i, k, p, q, t;
if(s==0)
return [v=f(v),v,v];
else{
i = Math.floor((h/60)%6);
k = (h/60)-i;
p = v*(1-s);
q = v*(1-k*s);
t = v*(1-(1-k)*s);
switch(i) {
case 0: r=v; g=t; b=p; break;
case 1: r=q; g=v; b=p; break;
case 2: r=p; g=v; b=t; break;
case 3: r=p; g=q; b=v; break;
case 4: r=t; g=p; b=v; break;
case 5: r=v; g=p; b=q; break;
}
return s==0?[v=f(v),v,v]:[f(r), f(g), f(b)];
}
},
// RGB [255,255,255] to HSV (h[0-360], s[0-1]), v[0-1]
rgb2hsv: function(r, g, b) {
if(r instanceof Array) {
g=r[1];b=r[2];r=r[0];
}
r=r/255;g=g/255;b=b/255;
var min=Math.min(r,g,b),
max=Math.max(r,g,b),
delta = max-min,
s = (max===0)?0:1-(min/max),
v = max,
h;
switch (max) {
case min:
h=0;
break;
case r:
h=60*(g-b)/delta;
if(g<b)h+=360;
break;
case g:
h=(60*(b-r)/delta)+120;
break;
case b:
h=(60*(r-g)/delta)+240;
break;
}
return [Math.round(h), s, v];
},
//rgb values into a hex string; 255,255,255 -> FFFFFF
rgb2hex: function(r, g, b) {
var ns=this;
if(r instanceof Array) {
g=r[1];b=r[2];r=r[0];
}
return ns._toFF(r) + ns._toFF(g) + ns._toFF(b);
},
// Converts a hex string to rgb
hex2rgb: function(hex) {
var ns=this;
if(!hex)hex="FFFFFF";
if(hex.charAt(0)=='#')hex=hex.slice(1);
return [ns._to255(hex.substr(0, 2)), ns._to255(hex.substr(2, 2)), ns._to255(hex.substr(4, 2))];
},
getTextColor:function(value){
value=this.hex2rgb(value);
value=this.rgb2hsv(value);
return (value&&value[2])>0.6?'#000000':'#FFFFFF';
},
_onresize:function(){}
}
});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -