mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
improve : color picker : initial implementation using spectrum
This commit is contained in:
parent
eb559eee0c
commit
f26b1d4ebc
477
css/spectrum/spectrum.css
Normal file
477
css/spectrum/spectrum.css
Normal file
@ -0,0 +1,477 @@
|
||||
/***
|
||||
Spectrum Colorpicker v1.1.2
|
||||
https://github.com/bgrins/spectrum
|
||||
Author: Brian Grinstead
|
||||
License: MIT
|
||||
***/
|
||||
|
||||
.sp-container {
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
display:inline-block;
|
||||
*display: inline;
|
||||
*zoom: 1;
|
||||
/* https://github.com/bgrins/spectrum/issues/40 */
|
||||
z-index: 9999994;
|
||||
overflow: hidden;
|
||||
}
|
||||
.sp-container.sp-flat {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* http://ansciath.tumblr.com/post/7347495869/css-aspect-ratio */
|
||||
.sp-top {
|
||||
position:relative;
|
||||
width: 100%;
|
||||
display:inline-block;
|
||||
}
|
||||
.sp-top-inner {
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
bottom:0;
|
||||
right:0;
|
||||
}
|
||||
.sp-color {
|
||||
position: absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
bottom:0;
|
||||
right:20%;
|
||||
}
|
||||
.sp-hue {
|
||||
position: absolute;
|
||||
top:0;
|
||||
right:0;
|
||||
bottom:0;
|
||||
left:84%;
|
||||
height: 100%;
|
||||
}
|
||||
.sp-fill {
|
||||
padding-top: 80%;
|
||||
}
|
||||
.sp-sat, .sp-val {
|
||||
position: absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
right:0;
|
||||
bottom:0;
|
||||
}
|
||||
|
||||
.sp-alpha-enabled .sp-top {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
.sp-alpha-enabled .sp-alpha {
|
||||
display: block;
|
||||
}
|
||||
.sp-alpha-handle {
|
||||
position:absolute;
|
||||
top:-4px;
|
||||
bottom: -4px;
|
||||
width: 6px;
|
||||
left: 50%;
|
||||
cursor: pointer;
|
||||
border: 1px solid black;
|
||||
background: white;
|
||||
opacity: .8;
|
||||
}
|
||||
.sp-alpha {
|
||||
display: none;
|
||||
position: absolute;
|
||||
bottom: -14px;
|
||||
right: 0;
|
||||
left: 0;
|
||||
height: 8px;
|
||||
}
|
||||
.sp-alpha-inner {
|
||||
border: solid 1px #333;
|
||||
}
|
||||
|
||||
/* Don't allow text selection */
|
||||
.sp-container, .sp-replacer, .sp-preview, .sp-dragger, .sp-slider, .sp-alpha, .sp-alpha-handle, .sp-container.sp-dragging .sp-input, .sp-container button {
|
||||
-webkit-user-select:none;
|
||||
-moz-user-select: -moz-none;
|
||||
-o-user-select:none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.sp-container.sp-input-disabled .sp-input-container {
|
||||
display: none;
|
||||
}
|
||||
.sp-container.sp-buttons-disabled .sp-button-container {
|
||||
display: none;
|
||||
}
|
||||
.sp-palette-only .sp-picker-container {
|
||||
display: none;
|
||||
}
|
||||
.sp-palette-disabled .sp-palette-container {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sp-initial-disabled .sp-initial {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
/* Gradients for hue, saturation and value instead of images. Not pretty... but it works */
|
||||
.sp-sat {
|
||||
background-image: -webkit-gradient(linear, 0 0, 100% 0, from(#FFF), to(rgba(204, 154, 129, 0)));
|
||||
background-image: -webkit-linear-gradient(left, #FFF, rgba(204, 154, 129, 0));
|
||||
background-image: -moz-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
|
||||
background-image: -o-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
|
||||
background-image: -ms-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
|
||||
background-image: linear-gradient(to right, #fff, rgba(204, 154, 129, 0));
|
||||
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType = 1, startColorstr=#FFFFFFFF, endColorstr=#00CC9A81)";
|
||||
filter : progid:DXImageTransform.Microsoft.gradient(GradientType = 1, startColorstr='#FFFFFFFF', endColorstr='#00CC9A81');
|
||||
}
|
||||
.sp-val {
|
||||
background-image: -webkit-gradient(linear, 0 100%, 0 0, from(#000000), to(rgba(204, 154, 129, 0)));
|
||||
background-image: -webkit-linear-gradient(bottom, #000000, rgba(204, 154, 129, 0));
|
||||
background-image: -moz-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
|
||||
background-image: -o-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
|
||||
background-image: -ms-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
|
||||
background-image: linear-gradient(to top, #000, rgba(204, 154, 129, 0));
|
||||
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00CC9A81, endColorstr=#FF000000)";
|
||||
filter : progid:DXImageTransform.Microsoft.gradient(startColorstr='#00CC9A81', endColorstr='#FF000000');
|
||||
}
|
||||
|
||||
.sp-hue {
|
||||
background: -moz-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
|
||||
background: -ms-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
|
||||
background: -o-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#ff0000), color-stop(0.17, #ffff00), color-stop(0.33, #00ff00), color-stop(0.5, #00ffff), color-stop(0.67, #0000ff), color-stop(0.83, #ff00ff), to(#ff0000));
|
||||
background: -webkit-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
|
||||
}
|
||||
|
||||
/* IE filters do not support multiple color stops.
|
||||
Generate 6 divs, line them up, and do two color gradients for each.
|
||||
Yes, really.
|
||||
*/
|
||||
.sp-1 {
|
||||
height:17%;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0000', endColorstr='#ffff00');
|
||||
}
|
||||
.sp-2 {
|
||||
height:16%;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffff00', endColorstr='#00ff00');
|
||||
}
|
||||
.sp-3 {
|
||||
height:17%;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ff00', endColorstr='#00ffff');
|
||||
}
|
||||
.sp-4 {
|
||||
height:17%;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ffff', endColorstr='#0000ff');
|
||||
}
|
||||
.sp-5 {
|
||||
height:16%;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0000ff', endColorstr='#ff00ff');
|
||||
}
|
||||
.sp-6 {
|
||||
height:17%;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff00ff', endColorstr='#ff0000');
|
||||
}
|
||||
|
||||
.sp-hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Clearfix hack */
|
||||
.sp-cf:before, .sp-cf:after { content: ""; display: table; }
|
||||
.sp-cf:after { clear: both; }
|
||||
.sp-cf { *zoom: 1; }
|
||||
|
||||
/* Mobile devices, make hue slider bigger so it is easier to slide */
|
||||
@media (max-device-width: 480px) {
|
||||
.sp-color { right: 40%; }
|
||||
.sp-hue { left: 63%; }
|
||||
.sp-fill { padding-top: 60%; }
|
||||
}
|
||||
.sp-dragger {
|
||||
border-radius: 5px;
|
||||
height: 5px;
|
||||
width: 5px;
|
||||
border: 1px solid #fff;
|
||||
background: #000;
|
||||
cursor: pointer;
|
||||
position:absolute;
|
||||
top:0;
|
||||
left: 0;
|
||||
}
|
||||
.sp-slider {
|
||||
position: absolute;
|
||||
top:0;
|
||||
cursor:pointer;
|
||||
height: 3px;
|
||||
left: -1px;
|
||||
right: -1px;
|
||||
border: 1px solid #000;
|
||||
background: white;
|
||||
opacity: .8;
|
||||
}
|
||||
|
||||
/*
|
||||
Theme authors:
|
||||
Here are the basic themeable display options (colors, fonts, global widths).
|
||||
See http://bgrins.github.io/spectrum/themes/ for instructions.
|
||||
*/
|
||||
|
||||
.sp-container {
|
||||
border-radius: 0;
|
||||
background-color: #ECECEC;
|
||||
border: solid 1px #f0c49B;
|
||||
padding: 0;
|
||||
}
|
||||
.sp-container, .sp-container button, .sp-container input, .sp-color, .sp-hue
|
||||
{
|
||||
font: normal 12px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
-ms-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.sp-top
|
||||
{
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.sp-color, .sp-hue
|
||||
{
|
||||
border: solid 1px #666;
|
||||
}
|
||||
|
||||
/* Input */
|
||||
.sp-input-container {
|
||||
float:right;
|
||||
width: 100px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.sp-initial-disabled .sp-input-container {
|
||||
width: 100%;
|
||||
}
|
||||
.sp-input {
|
||||
font-size: 12px !important;
|
||||
border: 1px inset;
|
||||
padding: 4px 5px;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
background:transparent;
|
||||
border-radius: 3px;
|
||||
color: #222;
|
||||
}
|
||||
.sp-input:focus {
|
||||
border: 1px solid orange;
|
||||
}
|
||||
.sp-input.sp-validation-error
|
||||
{
|
||||
border: 1px solid red;
|
||||
background: #fdd;
|
||||
}
|
||||
.sp-picker-container , .sp-palette-container
|
||||
{
|
||||
float:left;
|
||||
position: relative;
|
||||
padding: 10px;
|
||||
padding-bottom: 300px;
|
||||
margin-bottom: -290px;
|
||||
}
|
||||
.sp-picker-container
|
||||
{
|
||||
width: 172px;
|
||||
border-left: solid 1px #fff;
|
||||
}
|
||||
|
||||
/* Palettes */
|
||||
.sp-palette-container
|
||||
{
|
||||
border-right: solid 1px #ccc;
|
||||
}
|
||||
|
||||
.sp-palette .sp-thumb-el {
|
||||
display: block;
|
||||
position:relative;
|
||||
float:left;
|
||||
width: 24px;
|
||||
height: 15px;
|
||||
margin: 3px;
|
||||
cursor: pointer;
|
||||
border:solid 2px transparent;
|
||||
}
|
||||
.sp-palette .sp-thumb-el:hover, .sp-palette .sp-thumb-el.sp-thumb-active {
|
||||
border-color: orange;
|
||||
}
|
||||
.sp-thumb-el
|
||||
{
|
||||
position:relative;
|
||||
}
|
||||
|
||||
/* Initial */
|
||||
.sp-initial
|
||||
{
|
||||
float: left;
|
||||
border: solid 1px #333;
|
||||
}
|
||||
.sp-initial span {
|
||||
width: 30px;
|
||||
height: 25px;
|
||||
border:none;
|
||||
display:block;
|
||||
float:left;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.sp-button-container {
|
||||
float: right;
|
||||
}
|
||||
|
||||
/* Replacer (the little preview div that shows up instead of the <input>) */
|
||||
.sp-replacer {
|
||||
margin:0;
|
||||
overflow:hidden;
|
||||
cursor:pointer;
|
||||
padding: 4px;
|
||||
display:inline-block;
|
||||
*zoom: 1;
|
||||
*display: inline;
|
||||
border: solid 1px #91765d;
|
||||
background: #eee;
|
||||
color: #333;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.sp-replacer:hover, .sp-replacer.sp-active {
|
||||
border-color: #F0C49B;
|
||||
color: #111;
|
||||
}
|
||||
.sp-replacer.sp-disabled {
|
||||
cursor:default;
|
||||
border-color: silver;
|
||||
color: silver;
|
||||
}
|
||||
.sp-dd {
|
||||
padding: 2px 0;
|
||||
height: 16px;
|
||||
line-height: 16px;
|
||||
float:left;
|
||||
font-size:10px;
|
||||
}
|
||||
.sp-preview
|
||||
{
|
||||
position:relative;
|
||||
width:25px;
|
||||
height: 20px;
|
||||
border: solid 1px #222;
|
||||
margin-right: 5px;
|
||||
float:left;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.sp-palette
|
||||
{
|
||||
*width: 220px;
|
||||
max-width: 220px;
|
||||
}
|
||||
.sp-palette .sp-thumb-el
|
||||
{
|
||||
width:16px;
|
||||
height: 16px;
|
||||
margin:2px 1px;
|
||||
border: solid 1px #d0d0d0;
|
||||
}
|
||||
|
||||
.sp-container
|
||||
{
|
||||
padding-bottom:0;
|
||||
}
|
||||
|
||||
|
||||
/* Buttons: http://hellohappy.org/css3-buttons/ */
|
||||
.sp-container button {
|
||||
background-color: #eeeeee;
|
||||
background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
|
||||
background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
|
||||
background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);
|
||||
background-image: -o-linear-gradient(top, #eeeeee, #cccccc);
|
||||
background-image: linear-gradient(to bottom, #eeeeee, #cccccc);
|
||||
border: 1px solid #ccc;
|
||||
border-bottom: 1px solid #bbb;
|
||||
border-radius: 3px;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
padding: 5px 4px;
|
||||
text-align: center;
|
||||
text-shadow: 0 1px 0 #eee;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.sp-container button:hover {
|
||||
background-color: #dddddd;
|
||||
background-image: -webkit-linear-gradient(top, #dddddd, #bbbbbb);
|
||||
background-image: -moz-linear-gradient(top, #dddddd, #bbbbbb);
|
||||
background-image: -ms-linear-gradient(top, #dddddd, #bbbbbb);
|
||||
background-image: -o-linear-gradient(top, #dddddd, #bbbbbb);
|
||||
background-image: linear-gradient(to bottom, #dddddd, #bbbbbb);
|
||||
border: 1px solid #bbb;
|
||||
border-bottom: 1px solid #999;
|
||||
cursor: pointer;
|
||||
text-shadow: 0 1px 0 #ddd;
|
||||
}
|
||||
.sp-container button:active {
|
||||
border: 1px solid #aaa;
|
||||
border-bottom: 1px solid #888;
|
||||
-webkit-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
|
||||
-moz-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
|
||||
-ms-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
|
||||
-o-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
|
||||
box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
|
||||
}
|
||||
.sp-cancel
|
||||
{
|
||||
font-size: 11px;
|
||||
color: #d93f3f !important;
|
||||
margin:0;
|
||||
padding:2px;
|
||||
margin-right: 5px;
|
||||
vertical-align: middle;
|
||||
text-decoration:none;
|
||||
|
||||
}
|
||||
.sp-cancel:hover
|
||||
{
|
||||
color: #d93f3f !important;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
|
||||
.sp-palette span:hover, .sp-palette span.sp-thumb-active
|
||||
{
|
||||
border-color: #000;
|
||||
}
|
||||
|
||||
.sp-preview, .sp-alpha, .sp-thumb-el
|
||||
{
|
||||
position:relative;
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==);
|
||||
}
|
||||
.sp-preview-inner, .sp-alpha-inner, .sp-thumb-inner
|
||||
{
|
||||
display:block;
|
||||
position:absolute;
|
||||
top:0;left:0;bottom:0;right:0;
|
||||
}
|
||||
|
||||
.sp-palette .sp-thumb-inner
|
||||
{
|
||||
background-position: 50% 50%;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.sp-palette .sp-thumb-light.sp-thumb-active .sp-thumb-inner
|
||||
{
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAIVJREFUeNpiYBhsgJFMffxAXABlN5JruT4Q3wfi/0DsT64h8UD8HmpIPCWG/KemIfOJCUB+Aoacx6EGBZyHBqI+WsDCwuQ9mhxeg2A210Ntfo8klk9sOMijaURm7yc1UP2RNCMbKE9ODK1HM6iegYLkfx8pligC9lCD7KmRof0ZhjQACDAAceovrtpVBRkAAAAASUVORK5CYII=);
|
||||
}
|
||||
|
||||
.sp-palette .sp-thumb-dark.sp-thumb-active .sp-thumb-inner
|
||||
{
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAMdJREFUOE+tkgsNwzAMRMugEAahEAahEAZhEAqlEAZhEAohEAYh81X2dIm8fKpEspLGvudPOsUYpxE2BIJCroJmEW9qJ+MKaBFhEMNabSy9oIcIPwrB+afvAUFoK4H0tMaQ3XtlrggDhOVVMuT4E5MMG0FBbCEYzjYT7OxLEvIHQLY2zWwQ3D+9luyOQTfKDiFD3iUIfPk8VqrKjgAiSfGFPecrg6HN6m/iBcwiDAo7WiBeawa+Kwh7tZoSCGLMqwlSAzVDhoK+6vH4G0P5wdkAAAAASUVORK5CYII=);
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="css/forms.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/settings.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/tools.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/spectrum/spectrum.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-tooltip-custom.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/preview-film-section.css">
|
||||
|
@ -14,7 +14,7 @@ var Constants = {
|
||||
PREVIEW_FILM_SIZE : 120,
|
||||
|
||||
DEFAULT_PEN_COLOR : '#000000',
|
||||
TRANSPARENT_COLOR : 'TRANSPARENT',
|
||||
TRANSPARENT_COLOR : 'rgba(0, 0, 0, 0)',
|
||||
|
||||
/*
|
||||
* Fake semi-transparent color used to highlight transparent
|
||||
|
@ -18,17 +18,25 @@
|
||||
this.updateColorPicker_(color, $('#secondary-color-picker'));
|
||||
}, this));
|
||||
|
||||
var spectrumCfg = {
|
||||
showPalette: true,
|
||||
palette: [
|
||||
['rgba(0,0,0,0)']
|
||||
],
|
||||
clickoutFiresChange : true,
|
||||
beforeShow : function(tinycolor) {
|
||||
tinycolor.setAlpha(1);
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize colorpickers:
|
||||
var colorPicker = $('#color-picker');
|
||||
colorPicker.val(Constants.DEFAULT_PEN_COLOR);
|
||||
colorPicker.spectrum($.extend({color: Constants.DEFAULT_PEN_COLOR}, spectrumCfg));
|
||||
colorPicker.change({isPrimary : true}, $.proxy(this.onPickerChange_, this));
|
||||
|
||||
|
||||
var secondaryColorPicker = $('#secondary-color-picker');
|
||||
secondaryColorPicker.val(Constants.TRANSPARENT_COLOR);
|
||||
secondaryColorPicker.spectrum($.extend({color: Constants.TRANSPARENT_COLOR}, spectrumCfg));
|
||||
secondaryColorPicker.change({isPrimary : false}, $.proxy(this.onPickerChange_, this));
|
||||
|
||||
window.jscolor.install();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -64,17 +72,17 @@
|
||||
if (color == Constants.TRANSPARENT_COLOR) {
|
||||
// We can set the current palette color to transparent.
|
||||
// You can then combine this transparent color with an advanced
|
||||
// tool for customized deletions.
|
||||
// tool for customized deletions.
|
||||
// Eg: bucket + transparent: Delete a colored area
|
||||
// Stroke + transparent: hollow out the equivalent of a stroke
|
||||
|
||||
// The colorpicker can't be set to a transparent state.
|
||||
// We set its background to white and insert the
|
||||
// string "TRANSPARENT" to mimic this state:
|
||||
colorPicker[0].color.fromString("#fff");
|
||||
colorPicker.spectrum("set", Constants.TRANSPARENT_COLOR);
|
||||
colorPicker.val(Constants.TRANSPARENT_COLOR);
|
||||
} else {
|
||||
colorPicker[0].color.fromString(color);
|
||||
colorPicker.spectrum("set", color);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
BIN
js/lib/jsColor_1_4_0/.DS_Store
vendored
BIN
js/lib/jsColor_1_4_0/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 66 B |
Binary file not shown.
Before Width: | Height: | Size: 83 B |
@ -1,12 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>jscolor demo</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript" src="jscolor.js"></script>
|
||||
|
||||
Click here: <input class="color" value="66ff00">
|
||||
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB |
@ -1,927 +0,0 @@
|
||||
/**
|
||||
* jscolor, JavaScript Color Picker
|
||||
*
|
||||
* @version 1.4.0
|
||||
* @license GNU Lesser General Public License, http://www.gnu.org/copyleft/lesser.html
|
||||
* @author Jan Odvarko, http://odvarko.cz
|
||||
* @created 2008-06-15
|
||||
* @updated 2012-07-06
|
||||
* @link http://jscolor.com
|
||||
*/
|
||||
|
||||
|
||||
var jscolor = {
|
||||
|
||||
|
||||
dir : '', // location of jscolor directory (leave empty to autodetect)
|
||||
bindClass : 'color', // class name
|
||||
binding : true, // automatic binding via <input class="...">
|
||||
preloading : true, // use image preloading?
|
||||
|
||||
|
||||
install : function() {
|
||||
if (document.readyState === "complete") {
|
||||
jscolor.init();
|
||||
} else {
|
||||
jscolor.addEvent(window, 'load', jscolor.init);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
init : function() {
|
||||
if(jscolor.binding) {
|
||||
jscolor.bind();
|
||||
}
|
||||
if(jscolor.preloading) {
|
||||
jscolor.preload();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getDir : function() {
|
||||
return "/" + window.location.pathname.split("/")[1] + "/js/lib/jsColor_1_4_0/";
|
||||
},
|
||||
|
||||
|
||||
bind : function() {
|
||||
var matchClass = new RegExp('(^|\\s)('+jscolor.bindClass+')\\s*(\\{[^}]*\\})?', 'i');
|
||||
var e = document.getElementsByTagName('input');
|
||||
for(var i=0; i<e.length; i+=1) {
|
||||
var m;
|
||||
if(!e[i].color && e[i].className && (m = e[i].className.match(matchClass))) {
|
||||
var prop = {};
|
||||
if(m[3]) {
|
||||
try {
|
||||
prop = (new Function ('return (' + m[3] + ')'))();
|
||||
} catch(eInvalidProp) {}
|
||||
}
|
||||
e[i].color = new jscolor.color(e[i], prop);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
preload : function() {
|
||||
for(var fn in jscolor.imgRequire) {
|
||||
if(jscolor.imgRequire.hasOwnProperty(fn)) {
|
||||
jscolor.loadImage(fn);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
images : {
|
||||
pad : [ 181, 101 ],
|
||||
sld : [ 16, 101 ],
|
||||
cross : [ 15, 15 ],
|
||||
arrow : [ 7, 11 ]
|
||||
},
|
||||
|
||||
|
||||
imgRequire : {},
|
||||
imgLoaded : {},
|
||||
|
||||
|
||||
requireImage : function(filename) {
|
||||
jscolor.imgRequire[filename] = true;
|
||||
},
|
||||
|
||||
|
||||
loadImage : function(filename) {
|
||||
if(!jscolor.imgLoaded[filename]) {
|
||||
jscolor.imgLoaded[filename] = new Image();
|
||||
jscolor.imgLoaded[filename].src = jscolor.getDir()+filename;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
fetchElement : function(mixed) {
|
||||
return typeof mixed === 'string' ? document.getElementById(mixed) : mixed;
|
||||
},
|
||||
|
||||
|
||||
addEvent : function(el, evnt, func) {
|
||||
if(el.addEventListener) {
|
||||
el.addEventListener(evnt, func, false);
|
||||
} else if(el.attachEvent) {
|
||||
el.attachEvent('on'+evnt, func);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
fireEvent : function(el, evnt) {
|
||||
if(!el) {
|
||||
return;
|
||||
}
|
||||
if(document.createEvent) {
|
||||
var ev = document.createEvent('HTMLEvents');
|
||||
ev.initEvent(evnt, true, true);
|
||||
el.dispatchEvent(ev);
|
||||
} else if(document.createEventObject) {
|
||||
var ev = document.createEventObject();
|
||||
el.fireEvent('on'+evnt, ev);
|
||||
} else if(el['on'+evnt]) { // alternatively use the traditional event model (IE5)
|
||||
el['on'+evnt]();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getElementPos : function(e) {
|
||||
var e1=e, e2=e;
|
||||
var x=0, y=0;
|
||||
if(e1.offsetParent) {
|
||||
do {
|
||||
x += e1.offsetLeft;
|
||||
y += e1.offsetTop;
|
||||
} while(e1 = e1.offsetParent);
|
||||
}
|
||||
while((e2 = e2.parentNode) && e2.nodeName.toUpperCase() !== 'BODY') {
|
||||
x -= e2.scrollLeft;
|
||||
y -= e2.scrollTop;
|
||||
}
|
||||
return [x, y];
|
||||
},
|
||||
|
||||
|
||||
getElementSize : function(e) {
|
||||
return [e.offsetWidth, e.offsetHeight];
|
||||
},
|
||||
|
||||
|
||||
getRelMousePos : function(e) {
|
||||
var x = 0, y = 0;
|
||||
if (!e) { e = window.event; }
|
||||
if (typeof e.offsetX === 'number') {
|
||||
x = e.offsetX;
|
||||
y = e.offsetY;
|
||||
} else if (typeof e.layerX === 'number') {
|
||||
x = e.layerX;
|
||||
y = e.layerY;
|
||||
}
|
||||
return { x: x, y: y };
|
||||
},
|
||||
|
||||
|
||||
getViewPos : function() {
|
||||
if(typeof window.pageYOffset === 'number') {
|
||||
return [window.pageXOffset, window.pageYOffset];
|
||||
} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
|
||||
return [document.body.scrollLeft, document.body.scrollTop];
|
||||
} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
|
||||
return [document.documentElement.scrollLeft, document.documentElement.scrollTop];
|
||||
} else {
|
||||
return [0, 0];
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getViewSize : function() {
|
||||
if(typeof window.innerWidth === 'number') {
|
||||
return [window.innerWidth, window.innerHeight];
|
||||
} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
|
||||
return [document.body.clientWidth, document.body.clientHeight];
|
||||
} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
|
||||
return [document.documentElement.clientWidth, document.documentElement.clientHeight];
|
||||
} else {
|
||||
return [0, 0];
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
URI : function(uri) { // See RFC3986
|
||||
|
||||
this.scheme = null;
|
||||
this.authority = null;
|
||||
this.path = '';
|
||||
this.query = null;
|
||||
this.fragment = null;
|
||||
|
||||
this.parse = function(uri) {
|
||||
var m = uri.match(/^(([A-Za-z][0-9A-Za-z+.-]*)(:))?((\/\/)([^\/?#]*))?([^?#]*)((\?)([^#]*))?((#)(.*))?/);
|
||||
this.scheme = m[3] ? m[2] : null;
|
||||
this.authority = m[5] ? m[6] : null;
|
||||
this.path = m[7];
|
||||
this.query = m[9] ? m[10] : null;
|
||||
this.fragment = m[12] ? m[13] : null;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.toString = function() {
|
||||
var result = '';
|
||||
if(this.scheme !== null) { result = result + this.scheme + ':'; }
|
||||
if(this.authority !== null) { result = result + '//' + this.authority; }
|
||||
if(this.path !== null) { result = result + this.path; }
|
||||
if(this.query !== null) { result = result + '?' + this.query; }
|
||||
if(this.fragment !== null) { result = result + '#' + this.fragment; }
|
||||
return result;
|
||||
};
|
||||
|
||||
this.toAbsolute = function(base) {
|
||||
var base = new jscolor.URI(base);
|
||||
var r = this;
|
||||
var t = new jscolor.URI;
|
||||
|
||||
if(base.scheme === null) { return false; }
|
||||
|
||||
if(r.scheme !== null && r.scheme.toLowerCase() === base.scheme.toLowerCase()) {
|
||||
r.scheme = null;
|
||||
}
|
||||
|
||||
if(r.scheme !== null) {
|
||||
t.scheme = r.scheme;
|
||||
t.authority = r.authority;
|
||||
t.path = removeDotSegments(r.path);
|
||||
t.query = r.query;
|
||||
} else {
|
||||
if(r.authority !== null) {
|
||||
t.authority = r.authority;
|
||||
t.path = removeDotSegments(r.path);
|
||||
t.query = r.query;
|
||||
} else {
|
||||
if(r.path === '') {
|
||||
t.path = base.path;
|
||||
if(r.query !== null) {
|
||||
t.query = r.query;
|
||||
} else {
|
||||
t.query = base.query;
|
||||
}
|
||||
} else {
|
||||
if(r.path.substr(0,1) === '/') {
|
||||
t.path = removeDotSegments(r.path);
|
||||
} else {
|
||||
if(base.authority !== null && base.path === '') {
|
||||
t.path = '/'+r.path;
|
||||
} else {
|
||||
t.path = base.path.replace(/[^\/]+$/,'')+r.path;
|
||||
}
|
||||
t.path = removeDotSegments(t.path);
|
||||
}
|
||||
t.query = r.query;
|
||||
}
|
||||
t.authority = base.authority;
|
||||
}
|
||||
t.scheme = base.scheme;
|
||||
}
|
||||
t.fragment = r.fragment;
|
||||
|
||||
return t;
|
||||
};
|
||||
|
||||
function removeDotSegments(path) {
|
||||
var out = '';
|
||||
while(path) {
|
||||
if(path.substr(0,3)==='../' || path.substr(0,2)==='./') {
|
||||
path = path.replace(/^\.+/,'').substr(1);
|
||||
} else if(path.substr(0,3)==='/./' || path==='/.') {
|
||||
path = '/'+path.substr(3);
|
||||
} else if(path.substr(0,4)==='/../' || path==='/..') {
|
||||
path = '/'+path.substr(4);
|
||||
out = out.replace(/\/?[^\/]*$/, '');
|
||||
} else if(path==='.' || path==='..') {
|
||||
path = '';
|
||||
} else {
|
||||
var rm = path.match(/^\/?[^\/]*/)[0];
|
||||
path = path.substr(rm.length);
|
||||
out = out + rm;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
if(uri) {
|
||||
this.parse(uri);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
* Usage example:
|
||||
* var myColor = new jscolor.color(myInputElement)
|
||||
*/
|
||||
|
||||
color : function(target, prop) {
|
||||
|
||||
|
||||
this.required = true; // refuse empty values?
|
||||
this.adjust = true; // adjust value to uniform notation?
|
||||
this.hash = false; // prefix color with # symbol?
|
||||
this.caps = true; // uppercase?
|
||||
this.slider = true; // show the value/saturation slider?
|
||||
this.valueElement = target; // value holder
|
||||
this.styleElement = target; // where to reflect current color
|
||||
this.onImmediateChange = null; // onchange callback (can be either string or function)
|
||||
this.hsv = [0, 0, 1]; // read-only 0-6, 0-1, 0-1
|
||||
this.rgb = [1, 1, 1]; // read-only 0-1, 0-1, 0-1
|
||||
this.minH = 0; // read-only 0-6
|
||||
this.maxH = 6; // read-only 0-6
|
||||
this.minS = 0; // read-only 0-1
|
||||
this.maxS = 1; // read-only 0-1
|
||||
this.minV = 0; // read-only 0-1
|
||||
this.maxV = 1; // read-only 0-1
|
||||
|
||||
this.pickerOnfocus = true; // display picker on focus?
|
||||
this.pickerMode = 'HSV'; // HSV | HVS
|
||||
this.pickerPosition = 'bottom'; // left | right | top | bottom
|
||||
this.pickerSmartPosition = true; // automatically adjust picker position when necessary
|
||||
this.pickerButtonHeight = 20; // px
|
||||
this.pickerClosable = false;
|
||||
this.pickerCloseText = 'Close';
|
||||
this.pickerButtonColor = 'ButtonText'; // px
|
||||
this.pickerFace = 10; // px
|
||||
this.pickerFaceColor = 'ThreeDFace'; // CSS color
|
||||
this.pickerBorder = 1; // px
|
||||
this.pickerBorderColor = 'ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight'; // CSS color
|
||||
this.pickerInset = 1; // px
|
||||
this.pickerInsetColor = 'ThreeDShadow ThreeDHighlight ThreeDHighlight ThreeDShadow'; // CSS color
|
||||
this.pickerZIndex = 10000;
|
||||
|
||||
|
||||
for(var p in prop) {
|
||||
if(prop.hasOwnProperty(p)) {
|
||||
this[p] = prop[p];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.hidePicker = function() {
|
||||
if(isPickerOwner()) {
|
||||
removePicker();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.showPicker = function() {
|
||||
if(!isPickerOwner()) {
|
||||
var tp = jscolor.getElementPos(target); // target pos
|
||||
var ts = jscolor.getElementSize(target); // target size
|
||||
var vp = jscolor.getViewPos(); // view pos
|
||||
var vs = jscolor.getViewSize(); // view size
|
||||
var ps = getPickerDims(this); // picker size
|
||||
var a, b, c;
|
||||
switch(this.pickerPosition.toLowerCase()) {
|
||||
case 'left': a=1; b=0; c=-1; break;
|
||||
case 'right':a=1; b=0; c=1; break;
|
||||
case 'top': a=0; b=1; c=-1; break;
|
||||
default: a=0; b=1; c=1; break;
|
||||
}
|
||||
var l = (ts[b]+ps[b])/2;
|
||||
|
||||
// picker pos
|
||||
if (!this.pickerSmartPosition) {
|
||||
var pp = [
|
||||
tp[a],
|
||||
tp[b]+ts[b]-l+l*c
|
||||
];
|
||||
} else {
|
||||
var pp = [
|
||||
-vp[a]+tp[a]+ps[a] > vs[a] ?
|
||||
(-vp[a]+tp[a]+ts[a]/2 > vs[a]/2 && tp[a]+ts[a]-ps[a] >= 0 ? tp[a]+ts[a]-ps[a] : tp[a]) :
|
||||
tp[a],
|
||||
-vp[b]+tp[b]+ts[b]+ps[b]-l+l*c > vs[b] ?
|
||||
(-vp[b]+tp[b]+ts[b]/2 > vs[b]/2 && tp[b]+ts[b]-l-l*c >= 0 ? tp[b]+ts[b]-l-l*c : tp[b]+ts[b]-l+l*c) :
|
||||
(tp[b]+ts[b]-l+l*c >= 0 ? tp[b]+ts[b]-l+l*c : tp[b]+ts[b]-l-l*c)
|
||||
];
|
||||
}
|
||||
drawPicker(pp[a], pp[b]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.importColor = function() {
|
||||
if(!valueElement) {
|
||||
this.exportColor();
|
||||
} else {
|
||||
if(!this.adjust) {
|
||||
if(!this.fromString(valueElement.value, leaveValue)) {
|
||||
styleElement.style.backgroundImage = styleElement.jscStyle.backgroundImage;
|
||||
styleElement.style.backgroundColor = styleElement.jscStyle.backgroundColor;
|
||||
styleElement.style.color = styleElement.jscStyle.color;
|
||||
this.exportColor(leaveValue | leaveStyle);
|
||||
}
|
||||
} else if(!this.required && /^\s*$/.test(valueElement.value)) {
|
||||
valueElement.value = '';
|
||||
styleElement.style.backgroundImage = styleElement.jscStyle.backgroundImage;
|
||||
styleElement.style.backgroundColor = styleElement.jscStyle.backgroundColor;
|
||||
styleElement.style.color = styleElement.jscStyle.color;
|
||||
this.exportColor(leaveValue | leaveStyle);
|
||||
|
||||
} else if(this.fromString(valueElement.value)) {
|
||||
// OK
|
||||
} else {
|
||||
this.exportColor();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.exportColor = function(flags) {
|
||||
if(!(flags & leaveValue) && valueElement) {
|
||||
var value = this.toString();
|
||||
if(this.caps) { value = value.toUpperCase(); }
|
||||
if(this.hash) { value = '#'+value; }
|
||||
valueElement.value = value;
|
||||
}
|
||||
if(!(flags & leaveStyle) && styleElement) {
|
||||
styleElement.style.backgroundImage = "none";
|
||||
styleElement.style.backgroundColor =
|
||||
'#'+this.toString();
|
||||
styleElement.style.color =
|
||||
0.213 * this.rgb[0] +
|
||||
0.715 * this.rgb[1] +
|
||||
0.072 * this.rgb[2]
|
||||
< 0.5 ? '#FFF' : '#000';
|
||||
}
|
||||
if(!(flags & leavePad) && isPickerOwner()) {
|
||||
redrawPad();
|
||||
}
|
||||
if(!(flags & leaveSld) && isPickerOwner()) {
|
||||
redrawSld();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.fromHSV = function(h, s, v, flags) { // null = don't change
|
||||
if(h !== null) { h = Math.max(0.0, this.minH, Math.min(6.0, this.maxH, h)); }
|
||||
if(s !== null) { s = Math.max(0.0, this.minS, Math.min(1.0, this.maxS, s)); }
|
||||
if(v !== null) { v = Math.max(0.0, this.minV, Math.min(1.0, this.maxV, v)); }
|
||||
|
||||
this.rgb = HSV_RGB(
|
||||
h===null ? this.hsv[0] : (this.hsv[0]=h),
|
||||
s===null ? this.hsv[1] : (this.hsv[1]=s),
|
||||
v===null ? this.hsv[2] : (this.hsv[2]=v)
|
||||
);
|
||||
|
||||
this.exportColor(flags);
|
||||
};
|
||||
|
||||
|
||||
this.fromRGB = function(r, g, b, flags) { // null = don't change
|
||||
if(r !== null) { r = Math.max(0.0, Math.min(1.0, r)); }
|
||||
if(g !== null) { g = Math.max(0.0, Math.min(1.0, g)); }
|
||||
if(b !== null) { b = Math.max(0.0, Math.min(1.0, b)); }
|
||||
|
||||
var hsv = RGB_HSV(
|
||||
r===null ? this.rgb[0] : r,
|
||||
g===null ? this.rgb[1] : g,
|
||||
b===null ? this.rgb[2] : b
|
||||
);
|
||||
if(hsv[0] !== null) {
|
||||
this.hsv[0] = Math.max(0.0, this.minH, Math.min(6.0, this.maxH, hsv[0]));
|
||||
}
|
||||
if(hsv[2] !== 0) {
|
||||
this.hsv[1] = hsv[1]===null ? null : Math.max(0.0, this.minS, Math.min(1.0, this.maxS, hsv[1]));
|
||||
}
|
||||
this.hsv[2] = hsv[2]===null ? null : Math.max(0.0, this.minV, Math.min(1.0, this.maxV, hsv[2]));
|
||||
|
||||
// update RGB according to final HSV, as some values might be trimmed
|
||||
var rgb = HSV_RGB(this.hsv[0], this.hsv[1], this.hsv[2]);
|
||||
this.rgb[0] = rgb[0];
|
||||
this.rgb[1] = rgb[1];
|
||||
this.rgb[2] = rgb[2];
|
||||
|
||||
this.exportColor(flags);
|
||||
};
|
||||
|
||||
|
||||
this.fromString = function(hex, flags) {
|
||||
var m = hex.match(/^\W*([0-9A-F]{3}([0-9A-F]{3})?)\W*$/i);
|
||||
if(!m) {
|
||||
return false;
|
||||
} else {
|
||||
if(m[1].length === 6) { // 6-char notation
|
||||
this.fromRGB(
|
||||
parseInt(m[1].substr(0,2),16) / 255,
|
||||
parseInt(m[1].substr(2,2),16) / 255,
|
||||
parseInt(m[1].substr(4,2),16) / 255,
|
||||
flags
|
||||
);
|
||||
} else { // 3-char notation
|
||||
this.fromRGB(
|
||||
parseInt(m[1].charAt(0)+m[1].charAt(0),16) / 255,
|
||||
parseInt(m[1].charAt(1)+m[1].charAt(1),16) / 255,
|
||||
parseInt(m[1].charAt(2)+m[1].charAt(2),16) / 255,
|
||||
flags
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.toString = function() {
|
||||
return (
|
||||
(0x100 | Math.round(255*this.rgb[0])).toString(16).substr(1) +
|
||||
(0x100 | Math.round(255*this.rgb[1])).toString(16).substr(1) +
|
||||
(0x100 | Math.round(255*this.rgb[2])).toString(16).substr(1)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
function RGB_HSV(r, g, b) {
|
||||
var n = Math.min(Math.min(r,g),b);
|
||||
var v = Math.max(Math.max(r,g),b);
|
||||
var m = v - n;
|
||||
if(m === 0) { return [ null, 0, v ]; }
|
||||
var h = r===n ? 3+(b-g)/m : (g===n ? 5+(r-b)/m : 1+(g-r)/m);
|
||||
return [ h===6?0:h, m/v, v ];
|
||||
}
|
||||
|
||||
|
||||
function HSV_RGB(h, s, v) {
|
||||
if(h === null) { return [ v, v, v ]; }
|
||||
var i = Math.floor(h);
|
||||
var f = i%2 ? h-i : 1-(h-i);
|
||||
var m = v * (1 - s);
|
||||
var n = v * (1 - s*f);
|
||||
switch(i) {
|
||||
case 6:
|
||||
case 0: return [v,n,m];
|
||||
case 1: return [n,v,m];
|
||||
case 2: return [m,v,n];
|
||||
case 3: return [m,n,v];
|
||||
case 4: return [n,m,v];
|
||||
case 5: return [v,m,n];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function removePicker() {
|
||||
delete jscolor.picker.owner;
|
||||
document.getElementsByTagName('body')[0].removeChild(jscolor.picker.boxB);
|
||||
}
|
||||
|
||||
|
||||
function drawPicker(x, y) {
|
||||
if(!jscolor.picker) {
|
||||
jscolor.picker = {
|
||||
box : document.createElement('div'),
|
||||
boxB : document.createElement('div'),
|
||||
pad : document.createElement('div'),
|
||||
padB : document.createElement('div'),
|
||||
padM : document.createElement('div'),
|
||||
sld : document.createElement('div'),
|
||||
sldB : document.createElement('div'),
|
||||
sldM : document.createElement('div'),
|
||||
btn : document.createElement('div'),
|
||||
btnS : document.createElement('span'),
|
||||
btnT : document.createTextNode(THIS.pickerCloseText)
|
||||
};
|
||||
for(var i=0,segSize=4; i<jscolor.images.sld[1]; i+=segSize) {
|
||||
var seg = document.createElement('div');
|
||||
seg.style.height = segSize+'px';
|
||||
seg.style.fontSize = '1px';
|
||||
seg.style.lineHeight = '0';
|
||||
jscolor.picker.sld.appendChild(seg);
|
||||
}
|
||||
jscolor.picker.sldB.appendChild(jscolor.picker.sld);
|
||||
jscolor.picker.box.appendChild(jscolor.picker.sldB);
|
||||
jscolor.picker.box.appendChild(jscolor.picker.sldM);
|
||||
jscolor.picker.padB.appendChild(jscolor.picker.pad);
|
||||
jscolor.picker.box.appendChild(jscolor.picker.padB);
|
||||
jscolor.picker.box.appendChild(jscolor.picker.padM);
|
||||
jscolor.picker.btnS.appendChild(jscolor.picker.btnT);
|
||||
jscolor.picker.btn.appendChild(jscolor.picker.btnS);
|
||||
jscolor.picker.box.appendChild(jscolor.picker.btn);
|
||||
jscolor.picker.boxB.appendChild(jscolor.picker.box);
|
||||
}
|
||||
|
||||
var p = jscolor.picker;
|
||||
|
||||
// controls interaction
|
||||
p.box.onmouseup =
|
||||
p.box.onmouseout = function() { target.focus(); };
|
||||
p.box.onmousedown = function() { abortBlur=true; };
|
||||
p.box.onmousemove = function(e) {
|
||||
if (holdPad || holdSld) {
|
||||
holdPad && setPad(e);
|
||||
holdSld && setSld(e);
|
||||
if (document.selection) {
|
||||
document.selection.empty();
|
||||
} else if (window.getSelection) {
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
dispatchImmediateChange();
|
||||
}
|
||||
};
|
||||
p.padM.onmouseup =
|
||||
p.padM.onmouseout = function() { if(holdPad) { holdPad=false; jscolor.fireEvent(valueElement,'change'); } };
|
||||
p.padM.onmousedown = function(e) {
|
||||
// if the slider is at the bottom, move it up
|
||||
switch(modeID) {
|
||||
case 0: if (THIS.hsv[2] === 0) { THIS.fromHSV(null, null, 1.0); }; break;
|
||||
case 1: if (THIS.hsv[1] === 0) { THIS.fromHSV(null, 1.0, null); }; break;
|
||||
}
|
||||
holdPad=true;
|
||||
setPad(e);
|
||||
dispatchImmediateChange();
|
||||
};
|
||||
p.sldM.onmouseup =
|
||||
p.sldM.onmouseout = function() { if(holdSld) { holdSld=false; jscolor.fireEvent(valueElement,'change'); } };
|
||||
p.sldM.onmousedown = function(e) {
|
||||
holdSld=true;
|
||||
setSld(e);
|
||||
dispatchImmediateChange();
|
||||
};
|
||||
|
||||
// picker
|
||||
var dims = getPickerDims(THIS);
|
||||
p.box.style.width = dims[0] + 'px';
|
||||
p.box.style.height = dims[1] + 'px';
|
||||
|
||||
// picker border
|
||||
p.boxB.style.position = 'absolute';
|
||||
p.boxB.style.clear = 'both';
|
||||
p.boxB.style.left = x+'px';
|
||||
p.boxB.style.top = y+'px';
|
||||
p.boxB.style.zIndex = THIS.pickerZIndex;
|
||||
p.boxB.style.border = THIS.pickerBorder+'px solid';
|
||||
p.boxB.style.borderColor = THIS.pickerBorderColor;
|
||||
p.boxB.style.background = THIS.pickerFaceColor;
|
||||
|
||||
// pad image
|
||||
p.pad.style.width = jscolor.images.pad[0]+'px';
|
||||
p.pad.style.height = jscolor.images.pad[1]+'px';
|
||||
|
||||
// pad border
|
||||
p.padB.style.position = 'absolute';
|
||||
p.padB.style.left = THIS.pickerFace+'px';
|
||||
p.padB.style.top = THIS.pickerFace+'px';
|
||||
p.padB.style.border = THIS.pickerInset+'px solid';
|
||||
p.padB.style.borderColor = THIS.pickerInsetColor;
|
||||
|
||||
// pad mouse area
|
||||
p.padM.style.position = 'absolute';
|
||||
p.padM.style.left = '0';
|
||||
p.padM.style.top = '0';
|
||||
p.padM.style.width = THIS.pickerFace + 2*THIS.pickerInset + jscolor.images.pad[0] + jscolor.images.arrow[0] + 'px';
|
||||
p.padM.style.height = p.box.style.height;
|
||||
p.padM.style.cursor = 'crosshair';
|
||||
|
||||
// slider image
|
||||
p.sld.style.overflow = 'hidden';
|
||||
p.sld.style.width = jscolor.images.sld[0]+'px';
|
||||
p.sld.style.height = jscolor.images.sld[1]+'px';
|
||||
|
||||
// slider border
|
||||
p.sldB.style.display = THIS.slider ? 'block' : 'none';
|
||||
p.sldB.style.position = 'absolute';
|
||||
p.sldB.style.right = THIS.pickerFace+'px';
|
||||
p.sldB.style.top = THIS.pickerFace+'px';
|
||||
p.sldB.style.border = THIS.pickerInset+'px solid';
|
||||
p.sldB.style.borderColor = THIS.pickerInsetColor;
|
||||
|
||||
// slider mouse area
|
||||
p.sldM.style.display = THIS.slider ? 'block' : 'none';
|
||||
p.sldM.style.position = 'absolute';
|
||||
p.sldM.style.right = '0';
|
||||
p.sldM.style.top = '0';
|
||||
p.sldM.style.width = jscolor.images.sld[0] + jscolor.images.arrow[0] + THIS.pickerFace + 2*THIS.pickerInset + 'px';
|
||||
p.sldM.style.height = p.box.style.height;
|
||||
try {
|
||||
p.sldM.style.cursor = 'pointer';
|
||||
} catch(eOldIE) {
|
||||
p.sldM.style.cursor = 'hand';
|
||||
}
|
||||
|
||||
// "close" button
|
||||
function setBtnBorder() {
|
||||
var insetColors = THIS.pickerInsetColor.split(/\s+/);
|
||||
var pickerOutsetColor = insetColors.length < 2 ? insetColors[0] : insetColors[1] + ' ' + insetColors[0] + ' ' + insetColors[0] + ' ' + insetColors[1];
|
||||
p.btn.style.borderColor = pickerOutsetColor;
|
||||
}
|
||||
p.btn.style.display = THIS.pickerClosable ? 'block' : 'none';
|
||||
p.btn.style.position = 'absolute';
|
||||
p.btn.style.left = THIS.pickerFace + 'px';
|
||||
p.btn.style.bottom = THIS.pickerFace + 'px';
|
||||
p.btn.style.padding = '0 15px';
|
||||
p.btn.style.height = '18px';
|
||||
p.btn.style.border = THIS.pickerInset + 'px solid';
|
||||
setBtnBorder();
|
||||
p.btn.style.color = THIS.pickerButtonColor;
|
||||
p.btn.style.font = '12px sans-serif';
|
||||
p.btn.style.textAlign = 'center';
|
||||
try {
|
||||
p.btn.style.cursor = 'pointer';
|
||||
} catch(eOldIE) {
|
||||
p.btn.style.cursor = 'hand';
|
||||
}
|
||||
p.btn.onmousedown = function () {
|
||||
THIS.hidePicker();
|
||||
};
|
||||
p.btnS.style.lineHeight = p.btn.style.height;
|
||||
|
||||
// load images in optimal order
|
||||
switch(modeID) {
|
||||
case 0: var padImg = 'hs.png'; break;
|
||||
case 1: var padImg = 'hv.png'; break;
|
||||
}
|
||||
p.padM.style.backgroundImage = "url('"+jscolor.getDir()+"cross.gif')";
|
||||
p.padM.style.backgroundRepeat = "no-repeat";
|
||||
p.sldM.style.backgroundImage = "url('"+jscolor.getDir()+"arrow.gif')";
|
||||
p.sldM.style.backgroundRepeat = "no-repeat";
|
||||
p.pad.style.backgroundImage = "url('"+jscolor.getDir()+padImg+"')";
|
||||
p.pad.style.backgroundRepeat = "no-repeat";
|
||||
p.pad.style.backgroundPosition = "0 0";
|
||||
|
||||
// place pointers
|
||||
redrawPad();
|
||||
redrawSld();
|
||||
|
||||
jscolor.picker.owner = THIS;
|
||||
document.getElementsByTagName('body')[0].appendChild(p.boxB);
|
||||
}
|
||||
|
||||
|
||||
function getPickerDims(o) {
|
||||
var dims = [
|
||||
2*o.pickerInset + 2*o.pickerFace + jscolor.images.pad[0] +
|
||||
(o.slider ? 2*o.pickerInset + 2*jscolor.images.arrow[0] + jscolor.images.sld[0] : 0),
|
||||
o.pickerClosable ?
|
||||
4*o.pickerInset + 3*o.pickerFace + jscolor.images.pad[1] + o.pickerButtonHeight :
|
||||
2*o.pickerInset + 2*o.pickerFace + jscolor.images.pad[1]
|
||||
];
|
||||
return dims;
|
||||
}
|
||||
|
||||
|
||||
function redrawPad() {
|
||||
// redraw the pad pointer
|
||||
switch(modeID) {
|
||||
case 0: var yComponent = 1; break;
|
||||
case 1: var yComponent = 2; break;
|
||||
}
|
||||
var x = Math.round((THIS.hsv[0]/6) * (jscolor.images.pad[0]-1));
|
||||
var y = Math.round((1-THIS.hsv[yComponent]) * (jscolor.images.pad[1]-1));
|
||||
jscolor.picker.padM.style.backgroundPosition =
|
||||
(THIS.pickerFace+THIS.pickerInset+x - Math.floor(jscolor.images.cross[0]/2)) + 'px ' +
|
||||
(THIS.pickerFace+THIS.pickerInset+y - Math.floor(jscolor.images.cross[1]/2)) + 'px';
|
||||
|
||||
// redraw the slider image
|
||||
var seg = jscolor.picker.sld.childNodes;
|
||||
|
||||
switch(modeID) {
|
||||
case 0:
|
||||
var rgb = HSV_RGB(THIS.hsv[0], THIS.hsv[1], 1);
|
||||
for(var i=0; i<seg.length; i+=1) {
|
||||
seg[i].style.backgroundColor = 'rgb('+
|
||||
(rgb[0]*(1-i/seg.length)*100)+'%,'+
|
||||
(rgb[1]*(1-i/seg.length)*100)+'%,'+
|
||||
(rgb[2]*(1-i/seg.length)*100)+'%)';
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
var rgb, s, c = [ THIS.hsv[2], 0, 0 ];
|
||||
var i = Math.floor(THIS.hsv[0]);
|
||||
var f = i%2 ? THIS.hsv[0]-i : 1-(THIS.hsv[0]-i);
|
||||
switch(i) {
|
||||
case 6:
|
||||
case 0: rgb=[0,1,2]; break;
|
||||
case 1: rgb=[1,0,2]; break;
|
||||
case 2: rgb=[2,0,1]; break;
|
||||
case 3: rgb=[2,1,0]; break;
|
||||
case 4: rgb=[1,2,0]; break;
|
||||
case 5: rgb=[0,2,1]; break;
|
||||
}
|
||||
for(var i=0; i<seg.length; i+=1) {
|
||||
s = 1 - 1/(seg.length-1)*i;
|
||||
c[1] = c[0] * (1 - s*f);
|
||||
c[2] = c[0] * (1 - s);
|
||||
seg[i].style.backgroundColor = 'rgb('+
|
||||
(c[rgb[0]]*100)+'%,'+
|
||||
(c[rgb[1]]*100)+'%,'+
|
||||
(c[rgb[2]]*100)+'%)';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function redrawSld() {
|
||||
// redraw the slider pointer
|
||||
switch(modeID) {
|
||||
case 0: var yComponent = 2; break;
|
||||
case 1: var yComponent = 1; break;
|
||||
}
|
||||
var y = Math.round((1-THIS.hsv[yComponent]) * (jscolor.images.sld[1]-1));
|
||||
jscolor.picker.sldM.style.backgroundPosition =
|
||||
'0 ' + (THIS.pickerFace+THIS.pickerInset+y - Math.floor(jscolor.images.arrow[1]/2)) + 'px';
|
||||
}
|
||||
|
||||
|
||||
function isPickerOwner() {
|
||||
return jscolor.picker && jscolor.picker.owner === THIS;
|
||||
}
|
||||
|
||||
|
||||
function blurTarget() {
|
||||
if(valueElement === target) {
|
||||
THIS.importColor();
|
||||
}
|
||||
if(THIS.pickerOnfocus) {
|
||||
THIS.hidePicker();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function blurValue() {
|
||||
if(valueElement !== target) {
|
||||
THIS.importColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setPad(e) {
|
||||
var mpos = jscolor.getRelMousePos(e);
|
||||
var x = mpos.x - THIS.pickerFace - THIS.pickerInset;
|
||||
var y = mpos.y - THIS.pickerFace - THIS.pickerInset;
|
||||
switch(modeID) {
|
||||
case 0: THIS.fromHSV(x*(6/(jscolor.images.pad[0]-1)), 1 - y/(jscolor.images.pad[1]-1), null, leaveSld); break;
|
||||
case 1: THIS.fromHSV(x*(6/(jscolor.images.pad[0]-1)), null, 1 - y/(jscolor.images.pad[1]-1), leaveSld); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setSld(e) {
|
||||
var mpos = jscolor.getRelMousePos(e);
|
||||
var y = mpos.y - THIS.pickerFace - THIS.pickerInset;
|
||||
switch(modeID) {
|
||||
case 0: THIS.fromHSV(null, null, 1 - y/(jscolor.images.sld[1]-1), leavePad); break;
|
||||
case 1: THIS.fromHSV(null, 1 - y/(jscolor.images.sld[1]-1), null, leavePad); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function dispatchImmediateChange() {
|
||||
if (THIS.onImmediateChange) {
|
||||
var callback;
|
||||
if (typeof THIS.onImmediateChange === 'string') {
|
||||
callback = new Function (THIS.onImmediateChange);
|
||||
} else {
|
||||
callback = THIS.onImmediateChange;
|
||||
}
|
||||
callback.call(THIS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var THIS = this;
|
||||
var modeID = this.pickerMode.toLowerCase()==='hvs' ? 1 : 0;
|
||||
var abortBlur = false;
|
||||
var
|
||||
valueElement = jscolor.fetchElement(this.valueElement),
|
||||
styleElement = jscolor.fetchElement(this.styleElement);
|
||||
var
|
||||
holdPad = false,
|
||||
holdSld = false;
|
||||
var
|
||||
leaveValue = 1<<0,
|
||||
leaveStyle = 1<<1,
|
||||
leavePad = 1<<2,
|
||||
leaveSld = 1<<3;
|
||||
|
||||
// target
|
||||
jscolor.addEvent(target, 'focus', function() {
|
||||
if(THIS.pickerOnfocus) { THIS.showPicker(); }
|
||||
});
|
||||
jscolor.addEvent(target, 'blur', function() {
|
||||
if(!abortBlur) {
|
||||
window.setTimeout(function(){ abortBlur || blurTarget(); abortBlur=false; }, 0);
|
||||
} else {
|
||||
abortBlur = false;
|
||||
}
|
||||
});
|
||||
|
||||
// valueElement
|
||||
if(valueElement) {
|
||||
var updateField = function() {
|
||||
THIS.fromString(valueElement.value, leaveValue);
|
||||
dispatchImmediateChange();
|
||||
};
|
||||
jscolor.addEvent(valueElement, 'keyup', updateField);
|
||||
jscolor.addEvent(valueElement, 'input', updateField);
|
||||
jscolor.addEvent(valueElement, 'blur', blurValue);
|
||||
valueElement.setAttribute('autocomplete', 'off');
|
||||
}
|
||||
|
||||
// styleElement
|
||||
if(styleElement) {
|
||||
styleElement.jscStyle = {
|
||||
backgroundImage : styleElement.style.backgroundImage,
|
||||
backgroundColor : styleElement.style.backgroundColor,
|
||||
color : styleElement.style.color
|
||||
};
|
||||
}
|
||||
|
||||
// require images
|
||||
switch(modeID) {
|
||||
case 0: jscolor.requireImage('hs.png'); break;
|
||||
case 1: jscolor.requireImage('hv.png'); break;
|
||||
}
|
||||
jscolor.requireImage('cross.gif');
|
||||
jscolor.requireImage('arrow.gif');
|
||||
|
||||
this.importColor();
|
||||
}
|
||||
|
||||
};
|
1927
js/lib/spectrum/spectrum.js
Normal file
1927
js/lib/spectrum/spectrum.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -48,7 +48,7 @@
|
||||
var b = imgData[i+2];
|
||||
var a = imgData[i+3];
|
||||
if (a < 125) {
|
||||
frame[x][y] = "TRANSPARENT";
|
||||
frame[x][y] = Constants.TRANSPARENT_COLOR;
|
||||
} else {
|
||||
frame[x][y] = this.rgbToHex(r,g,b);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ exports.scripts = [
|
||||
// GIF Encoding libraries
|
||||
"js/lib/gif/gif.worker.js",
|
||||
"js/lib/gif/gif.js",
|
||||
"js/lib/spectrum/spectrum.js",
|
||||
|
||||
// Application wide configuration
|
||||
"js/Constants.js",
|
||||
@ -21,7 +22,6 @@ exports.scripts = [
|
||||
"js/utils/Serializer.js",
|
||||
"js/utils/Template.js",
|
||||
"js/utils/UserSettings.js",
|
||||
"js/lib/jsColor_1_4_0/jscolor.js",
|
||||
|
||||
// Application libraries-->
|
||||
"js/rendering/DrawingLoop.js",
|
||||
|
@ -4,8 +4,8 @@
|
||||
<ul id="tools-container" class="tools-wrapper"></ul>
|
||||
<div class="palette-wrapper">
|
||||
<div class="tool-icon tool-color-picker">
|
||||
<input id="color-picker" class="color {hash:true}" type="text" value="" />
|
||||
<input id="secondary-color-picker" class="secondary-color-picker color {hash:true}" type="text" value="" />
|
||||
<input id="color-picker" class="color" type="text"/>
|
||||
<input id="secondary-color-picker" class="secondary-color-picker color" type="text" />
|
||||
</div>
|
||||
<div class="tool-icon tool-palette">
|
||||
<div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user