(function($){
var bigColorPicker = new function(){
var currentPicker = null; //当前绑定拾取器的对象
var allColorArray = [];//整个颜色区域分为前两列,后面所有列分为6个块,计算出各个区域的数组后放入一个总的二维数组里
var sideLength = 6;//六个区域的每个边长
this.init = function(){
$("body").append('
');
$("#bigLayout").hover(function(){
$(this).show();
},function(){
$(this).hide();
}).click(function(){
$("#bigpicker").hide();
});
//颜色拾取器text输入框注册事件
$("#bigHexColorText").keypress(function(){
var text = $.trim($(this).val());
$(this).val(text.replace(/[^A-Fa-f0-9#]/g,''));
if(text.length <= 0)return;
text = text.charAt(0)=='#'?text:"#" + text;
var countChar = 7 - text.length;
if(countChar < 0){
text = text.substring(0,7);
}else if(countChar > 0){
for(var i=0;i 0 && $("#bigpicker").length <= 0){
bigColorPicker.init();
}
var sl_ = parseInt(sideLength_,10);
if(engine == "L" && !isNaN(sl_) && sl_ >=2 && sl_ <= 10){
sideLength = sl_;
}else{
sideLength = 6;
}
this.getAllColorArray = function(){
allColorArray = new Array(sideLength*3 + 2);
//计算第一列的数组
var mixColorArray = [];
var blackWhiteGradientArray = gradientColor(new RGB(0,0,0),new RGB(255,255,255));
for(var i=0;i");
for(var j=0;j");
}
ulArray.push("");
}
$("#bigSections").html(ulArray.join(""));
var minBigpickerHeight = 90;
var minBigpickerWidth = 129;
var minSectionsHeight = minBigpickerHeight - 29;
var minSectionsWidth = minBigpickerWidth - 1;
var defaultSectionsWidth = (sideLength*3 + 2)*11 + 1;
if(defaultSectionsWidth < minSectionsWidth){
$("#bigSections li,#bigLayout").width(minSectionsWidth/(sideLength*3 + 2) - 2)
.height(minSectionsHeight/(sideLength*2) - 1);
$("#bigpicker").height(minBigpickerHeight).width(minBigpickerWidth);
$("#bigSections").height(minSectionsHeight).width(minSectionsWidth);
}else{
$("#bigSections").width(defaultSectionsWidth)
.height(sideLength*2*11);
$("#bigpicker").width(defaultSectionsWidth + 5)
.height(sideLength*2*11 + 29);
}
$("#bigSections ul").find("li:last").css("border-bottom","1px solid #000000");
$("#bigSections ul:last li").css("border-right","1px solid #000000");
$("#bigSections li").hover(function(){
var $this = $(this);
$("#bigLayout").css({"left":$this.position().left,"top":$this.position().top}).show();
var cor = $this.attr("data-color");
$("#bigBgshowDiv").css("backgroundColor",cor);
$("#bigHexColorText").val(cor);
invokeCallBack(cor);
},function(){
$("#bigLayout").hide();
});
}else{
//预加载图片
var bgmage = new Image();
bgmage.src = "../images/big_bgcolor.jpg";
//初始化为默认样式
$("#bigSections").height(134).width(222).addClass("bigpicker-bgimage").empty();
$("#bigpicker").width(227).height(163);
//P模式时鼠标在颜色小格上移动时获取颜色
$("#bigSections").unbind("mousemove").unbind("mouseout").mousemove(function(event){
var xSections = getSections(sideLength*3 + 2);
var ySections = getSections(sideLength*3);
var $this = $(this);
var cursorXPos = event.pageX - $this.offset().left;
var cursorYPos = event.pageY - $this.offset().top;
var xi = 0;
var yi = 0;
for(var i=0;i<(sideLength*3+2);i++){
if(cursorXPos >= xSections[i][0] && cursorXPos <= xSections[i][1]){
xi = i;
break;
}
}
for(var i=0;i<(sideLength*3);i++){
if(cursorYPos >= ySections[i][0] && cursorYPos <= ySections[i][1]){
yi = i;
break;
}
}
$("#bigLayout").css({"left":$this.position().left + xi*11,"top":$this.position().top + yi*11}).show();
var hex = allColorArray[xi][yi];
$("#bigBgshowDiv").css("backgroundColor",hex);
$("#bigHexColorText").val(hex);
invokeCallBack(hex);
}).mouseout(function(){
$("#bigLayout").hide();
});
}
//给传入的拾取颜色的元素绑定click事件,显示颜色拾取器
$(this).bind("click",function(event){
currentPicker = event.currentTarget;
$("#bigBgshowDiv").css("backgroundColor","#000000");
$("#bigHexColorText").val("#000000");
var pos = calculatePosition ($(currentPicker));
$("#bigpicker").css({"left":pos.left + "px","top":pos.top + "px"}).fadeIn(300);
var bigSectionsP = $("#bigSections").position();
$("#bigLayout").css({"left":bigSectionsP.left,"top":bigSectionsP.top}).show();
});
};
this.hidePicker = function(){
$("#bigpicker").hide();
};
this.movePicker = function(){
var pos = calculatePosition ($(currentPicker));
$("#bigpicker").css({"left":pos.left + "px","top":pos.top + "px"});
$("#bigLayout").hide();
};
//计算出拾取器层的left,top坐标
function calculatePosition ($el) {
var offset = $el.offset();
var compatMode = document.compatMode == 'CSS1Compat';
var w = compatMode ? document.documentElement.clientWidth : document.body.clientWidth;
var h = compatMode ? document.documentElement.clientHeight : document.body.clientHeight;
var pos = {left:offset.left,top:offset.top + $el.height() + 7};
var $bigpicker = $("#bigpicker");
if(offset.left + $bigpicker.width() > w){
pos.left = offset.left - $bigpicker.width() - 7;
if(pos.left < 0){
pos.left = 0;
}
}
if(offset.top + $el.height() + 7 + $bigpicker.height() > h){
pos.top = offset.top - $bigpicker.height() - 7;
if(pos.top < 0){
pos.top = 0;
}
}
return pos;
}
//创建小区域的四个角的颜色二维数组
function generateBlockcornerColor(r){
var a = new Array(2);
a[0] = [new RGB(r,0,0),new RGB(r,255,0)];
a[1] = [new RGB(r,0,255),new RGB(r,255,255)];
return a;
}
//两个颜色的渐变颜色数组
function gradientColor(startColor,endColor){
var gradientArray = [];
gradientArray[0] = startColor;
gradientArray[sideLength-1] = endColor;
var averageR = Math.round((endColor.r - startColor.r)/sideLength);
var averageG = Math.round((endColor.g - startColor.g)/sideLength);
var averageB = Math.round((endColor.b - startColor.b)/sideLength);
for(var i=1;i