Colors = function (objectId, inputTextId, styleColor, pallete) // конструктор { this._object = document.getElementById(objectId); this._objectId = objectId; this.inputText = document.getElementById(inputTextId); this.inputTextId = inputTextId; this.styleColor = styleColor; eval('this.oldColor = Colors.rgb2hex(this._object.style.'+styleColor+')'); this.inputText.value = this.oldColor; this.pallete = pallete; } Colors.prototype.show = function () // рисуем палитру { var table = ''; table += ''; table += ''; table += ''; table += ''; document.writeln(table); } Colors.rgb2hex = function (rgb) { // вспомогательная функция преобразование из формата rgb(0,0,0) в hex if (!rgb) { return '000000'; } if (rgb.substring(0,1)=="#") { return rgb.substring(1); } else { var s,i,h='', x='0123456789abcdef'; var c = rgb.substring(4); c = c.substring(0, c.length-1); if(c){ s=c.split(','); for (i=0; i < 3; i++){ n = parseInt(s[i]); h += x.charAt(n>>4) + x.charAt(n&15); } return h; } } } Colors.changecolor = function (thiscolor, _object, inputText, styleColor) { eval('document.getElementById(_object).style.'+styleColor+' = thiscolor'); document.getElementById(inputText).value = Colors.rgb2hex(thiscolor); } Colors.setup = function (params) { function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } }; param_default("rows", 5); param_default("cols", 12); param_default("width", 20); param_default("border", 1); param_default("styleColor", "color"); param_default("inputTextId", null); param_default("objectId", null); param_default("pallete", new Array ( '#FFFFCC', '#FFFF66', '#FFCC66', '#F2984C', '#E1771E', '#B47B10', '#A9501B', '#6F3C1B', '#804000', '#FF0000', '#940F04', '#660000', '#C3D9FF', '#99C9FF', '#66B5FF', '#3D81EE', '#0066CC', '#6C82B5', '#32527A', '#2D6E89', '#006699', '#215670', '#003366', '#000033', '#CAF99B', '#80FF00', '#00FF80', '#78B749', '#2BA94F', '#38B63C', '#0D8F63', '#2D8930', '#1B703A', '#11593C', '#063E3F', '#002E3F', '#FFBBE8', '#E895CC', '#FF6FCF', '#C94093', '#9D1961', '#800040', '#800080', '#72179D', '#6728B2', '#6131BD', '#341473', '#400058', '#FFFFFF', '#E6E6E6', '#CCCCCC', '#B3B3B3', '#999999', '#808080', '#7F7F7F', '#666666', '#4C4C4C', '#333333', '#191919', '#000000' )); param_default("outImage", "rgb.gif"); param_default("overImage", "on_rgb.gif"); var col = new Colors(params.objectId, params.inputTextId, params.styleColor, params.pallete); col.rows = params.rows; col.cols = params.cols; col.width = params.width; col.border = params.border; col.allwidth = col.cols*(col.width+col.border*4)+col.border; col.outImage = params.outImage col.overImage = params.overImage col.show(); return col; }