/*
* (c) 2005-2011 Richard Cowin (http://openrico.org)
* (c) 2005-2011 Matt Brown (http://dowdybrown.com)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
// ===================================================================
// Adapted to Rico by Matt Brown from code
// published by Matt Kruse http://www.mattkruse.com/
// ===================================================================
Rico.ColorPicker = function(id,options) {
this.initialize(id,options);
};
Rico.ColorPicker.prototype = {
/**
* @class Implements a pop-up color picker control.
* @extends Rico.Popup
* @constructs
* @param id unique identifier
* @param options object may contain any of the following:
* - showColorCode
- show hex color code as user hovers over color grid? default=false
* - cellsPerRow
- number of colors per row in the grid? default=18
* - palette
- array of 6 digit hex values, default=216 "web safe" colors
*
*/
initialize: function(id,options) {
this.id=id;
this.currentValue = "#FFFFFF";
Rico.extend(this, new Rico.Popup());
Rico.extend(this.options, {
showColorCode : false,
cellsPerRow : 18,
palette : []
});
var hexvals=['00','33','66','99','CC','FF'];
for (var g=0; g"; }
cp_contents += ' | ';
if ( ((i+1)>=this.options.palette.length) || (((i+1) % width) == 0)) {
cp_contents += "";
}
}
var halfwidth = Math.floor(width/2);
if (this.options.showColorCode) {
cp_contents += " | #FFFFFF |
";
} else {
cp_contents += " |
";
}
cp_contents += "";
this.content.innerHTML=cp_contents;
/**
* alias for openPopup
* @function
*/
this.open=this.openPopup;
/**
* alias for closePopup
* @function
*/
this.close=this.closePopup;
Rico.eventBind(this.container,"mouseover", Rico.eventHandle(this,'highlightColor'), false);
Rico.eventBind(this.container,"click", Rico.eventHandle(this,'selectColor'), false);
this.close();
},
/** @private */
selectColor: function(e) {
Rico.eventStop(e);
if (this.returnValue) this.returnValue(this.currentValue);
this.close();
},
/* This function runs when you move your mouse over a color block */
/** @private */
highlightColor: function(e) {
var elem = Rico.eventElement(e);
if (!elem.tagName || elem.tagName.toLowerCase() != 'td') return;
var c=Rico.Color.createColorFromBackground(elem).toString();
this.currentValue = c;
Rico.setStyle('colorPickerSelectedColor', {backgroundColor:c});
var d = Rico.$("colorPickerSelectedColorValue");
if (d) d.innerHTML = c;
}
};