dhtmlxColorPicker can be initialized on page either based on DIV element (in this case, its position is defined by position of this DIV), or attached to some text input (in this case, the position of the Color Picker will be assigned to the position of the INPUT element taking its visibility on page into account). So,the following ways of initialization are available for users of dhtmlxColorPicker:
The first things that need to be done for any type of dhtmlxColorPicker's initialization are the following:
<head> <link rel="stylesheet" type="text/css" href="[full path to this file]/dhtmlxcolorpicker.css"> <script src="[full path to this file]/dhtmlxcolorpicker.js"></script> </script>
There are two ways to set image path in dhtmlxColorPicker:
<script> myCP.setImagePath("[full path to this category]/codeabse/imgs/"); // should be used after creation of color picker's object </script>
<head> ... <script src="[full path to this file]/dhtmlxcolorpicker.js"></script> <script>window.dhx_globalImgPath="[full path to this category]/codebase/imgs/";</script> // sets image path </head>
The user needs to create an object where dhtmlxColorPicker will be placed later. In this example the object is a <div> element on page which is placed in the <body> tag:
<div id="colorPicker" style="position:absolute;top:150px;left:200px;"></div>
The next step is to create a new dhtmlXColorPicker and place it after the <div> element (object) that we've just created:
<script> var myCP = new dhtmlXColorPicker(container, isClickOnly, customColors, hide, fullview); </script>
The parameters the user should indicate are as follows:
And the last command that should be called in order to initialize the component is:
<script> myCP.init(); </script>
When the page is loaded, a color picker will be displayed on page with the current color selected in it.
There is also the possibility to create a Color Picker linked to an input on page. First, the user should create the input itself, for example:
<input type="text" id="colorPicker" colorbox="true" customcolors="true" selectonclick="true" fullview="true" selectedcolor="#00ff00">
The parameters of the input are:
And then, the following code creates the Color Picker and links in to the newly created input:
<script> myCP = dhtmlXColorPickerInput("сolorPicker"); myCP.init(); </script>
The color picker will be activated when the user clicks somewhere in the input. When the necessary color is chosen, and button “Select” pressed, the color picker closes. The code of the chosen color is displayed in the input (for example, 77e5cd). Also, the chosen color itself can be displayed in the colorbox (in case the input has colorbox=“true”).