-
+
ColorPicker Style
+
+
+
Chrome Devtool Style
+
+
+
+
+
Default Html Sample
@@ -365,6 +379,7 @@
Color Scales
},
colorpicker : {
mode : 'edit',
+ type: 'sketch',
hideDelay: 1000000
}
});
@@ -469,12 +484,13 @@ Color Scales
var type = item.getAttribute('data-type');
- for(var j = 0; j < 3; j++) {
- var picker = new CodeMirrorColorPicker[type]({
- target: item,
+ for(var j = 0; j < 1; j++) {
+ var picker = new CodeMirrorColorPicker.ColorPicker({
+ container: item,
+ type: type,
color: 'blue',
onChange : function (c) {
- console.log(c);
+ console.log(this, c);
}
});
}
diff --git a/package.json b/package.json
index 813fc2c..8fe1b93 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "codemirror-colorpicker",
- "version": "1.6.2",
+ "version": "1.6.3",
"description": "colorpicker for codemirror",
"main": "./dist/codemirror-colorpicker.js",
"scripts": {
diff --git a/resources/image/sketch-type.png b/resources/image/sketch-type.png
new file mode 100644
index 0000000..974ac62
Binary files /dev/null and b/resources/image/sketch-type.png differ
diff --git a/src/colorpicker/ColorInformation.js b/src/colorpicker/ColorInformation.js
index 51c1727..28b2cbb 100644
--- a/src/colorpicker/ColorInformation.js
+++ b/src/colorpicker/ColorInformation.js
@@ -213,9 +213,12 @@ export default class ColorInformation extends EventMachin {
var rgb = null;
if (format == 'hex') {
this.$hexCode.val(this.convertHEX());
+ var rgb = this.convertRGB();
+ this.setRGBInput(rgb.r, rgb.g, rgb.b, rgb.a);
} else if (format == 'rgb') {
var rgb = this.convertRGB();
this.setRGBInput(rgb.r, rgb.g, rgb.b, rgb.a);
+ this.$hexCode.val(this.convertHEX());
} else if (format == 'hsl') {
var hsl = this.convertHSL();
this.setHSLInput(hsl.h, hsl.s, hsl.l, hsl.a);
@@ -268,6 +271,7 @@ export default class ColorInformation extends EventMachin {
if(code.charAt(0) == '#' && code.length == 7) {
this.colorpicker.changeInformationColor(code);
+ this.setInputColor();
}
}
diff --git a/src/colorpicker/ColorPalette.js b/src/colorpicker/ColorPalette.js
index 90e15ea..7ea984b 100644
--- a/src/colorpicker/ColorPalette.js
+++ b/src/colorpicker/ColorPalette.js
@@ -52,10 +52,10 @@ export default class ColorPallet extends EventMachin {
setMainColor(e) {
e.preventDefault();
- var pos = this.colorpicker.$root.position(); // position for screen
- var w = this.$el.width();
- var h = this.$el.height();
-
+ var pos = this.$el.position(); // position for screen
+ var w = this.$el.width() - this.$el.cssFloat('padding-left') - this.$el.cssFloat('padding-right');
+ var h = this.$el.height() - this.$el.cssFloat('padding-top') - this.$el.cssFloat('padding-bottom');
+
var x = e.clientX - pos.left;
var y = e.clientY - pos.top;
diff --git a/src/colorpicker/index.js b/src/colorpicker/index.js
index 6f8e88f..9bc59d1 100644
--- a/src/colorpicker/index.js
+++ b/src/colorpicker/index.js
@@ -12,10 +12,10 @@ import CurrentColorSets from './CurrentColorSets'
import CurrentColorSetsContextMenu from './CurrentColorSetsContextMenu'
export default class ColorPicker extends EventMachin {
- constructor (opt) {
+ constructor(opt) {
super();
- this.opt = opt || {};
+ this.opt = opt || {};
this.$body = null;
this.$root = null;
this.format = 'rgb';
@@ -23,14 +23,14 @@ export default class ColorPicker extends EventMachin {
this.currentH = 0;
this.currentS = 0;
this.currentV = 0;
- this.colorSetsList = new ColorSetsList(this);
- this.colorpickerCallback = function () {};
+ this.colorSetsList = new ColorSetsList(this);
+ this.colorpickerCallback = function () { };
this.isColorPickerShow = false;
this.isShortCut = false;
this.hideDelay = this.opt.hideDeplay || 2000;
this.timerCloseColorPicker;
- this.autoHide = this.opt.autoHide || true;
+ this.autoHide = this.opt.autoHide || true;
this.control = new ColorControl(this);
this.palette = new ColorPalette(this);
@@ -42,14 +42,25 @@ export default class ColorPicker extends EventMachin {
this.initialize();
}
- getOption (key) {
+ getOption(key) {
return this.opt[key];
}
- initialize () {
- this.$body = new Dom(this.opt.container || document.body);
+ getContainer () {
+ return this.opt.container || document.body;
+ }
+
+ initialize() {
+ this.$body = new Dom(this.getContainer());
this.$root = new Dom('div', 'codemirror-colorpicker');
+ // append colorpicker to container (ex : body)
+ this.$body.append(this.$root);
+
+ if (this.opt.type) { // to change css style
+ this.$root.addClass(this.opt.type);
+ }
+
this.$arrow = new Dom('div', 'arrow');
@@ -60,24 +71,27 @@ export default class ColorPicker extends EventMachin {
this.$root.append(this.currentColorSets.$el);
this.$root.append(this.colorSetsChooser.$el);
this.$root.append(this.contextMenu.$el);
-
- this.$checkColorPickerClass = this.checkColorPickerClass.bind(this);
- this.initColor();
+ this.$checkColorPickerClass = this.checkColorPickerClass.bind(this);
+
+ this.initColor(this.opt.color);
+
+ // register all events
+ this.initializeEvent();
}
- showContextMenu (e, index) {
+ showContextMenu(e, index) {
this.contextMenu.show(e, index);
}
setColor(value) {
- if(typeof(value) == "object") {
- if(!value.r || !value.g || !value.b)
+ if (typeof (value) == "object") {
+ if (!value.r || !value.g || !value.b)
return;
this.initColor(Color.format(value, "hex"));
- } else if(typeof(value) == "string") {
- this.initColor(value);
+ } else if (typeof (value) == "string") {
+ this.initColor(value);
}
}
@@ -92,24 +106,24 @@ export default class ColorPicker extends EventMachin {
return rgb;
}
- definePositionForArrow (opt, elementScreenLeft, elementScreenTop) {
+ definePositionForArrow(opt, elementScreenLeft, elementScreenTop) {
//this.$arrow.css({})
}
- definePosition (opt) {
+ definePosition(opt) {
var width = this.$root.width();
var height = this.$root.height();
// set left position for color picker
- var elementScreenLeft = opt.left - this.$body.el.scrollLeft ;
+ var elementScreenLeft = opt.left - this.$body.el.scrollLeft;
if (width + elementScreenLeft > window.innerWidth) {
elementScreenLeft -= (width + elementScreenLeft) - window.innerWidth;
}
if (elementScreenLeft < 0) { elementScreenLeft = 0; }
// set top position for color picker
- var elementScreenTop = opt.top - this.$body.el.scrollTop ;
+ var elementScreenTop = opt.top - this.$body.el.scrollTop;
if (height + elementScreenTop > window.innerHeight) {
elementScreenTop -= (height + elementScreenTop) - window.innerHeight;
}
@@ -118,32 +132,48 @@ export default class ColorPicker extends EventMachin {
// set position
this.$root.css({
- left : (elementScreenLeft) + 'px',
- top : (elementScreenTop) + 'px'
+ left: (elementScreenLeft) + 'px',
+ top: (elementScreenTop) + 'px'
});
}
- show (opt, color, callback) {
+ getInitalizePosition() {
+ if (this.opt.position == 'inline') {
+ return {
+ position: 'relative',
+ left: 'auto',
+ top: 'auto',
+ display: 'inline-block'
+ }
+ } else {
+ return {
+ position: 'fixed', // color picker has fixed position
+ left: '-10000px',
+ top: '-10000px'
+ }
+ }
+ }
+
+ show(opt, color, callback) {
this.destroy();
this.initializeEvent();
- this.$root.appendTo(document.body);
+ this.$root.appendTo(this.$body);
- this.$root.css({
- position: 'fixed', // color picker has fixed position
- left : '-10000px',
- top : '-10000px'
- }).show();
+ this.$root.css(this.getInitalizePosition()).show();
this.definePosition(opt);
this.isColorPickerShow = true;
this.isShortCut = opt.isShortCut || false;
-
+
this.initColor(color);
// define colorpicker callback
- this.colorpickerCallback = function (colorString) {
+ this.colorpickerCallback = (colorString) => {
+ if (typeof this.opt.onChange == 'function') {
+ this.opt.onChange(colorString);
+ }
callback(colorString);
}
@@ -155,7 +185,7 @@ export default class ColorPicker extends EventMachin {
}
- setHideDelay (delayTime) {
+ setHideDelay(delayTime) {
delayTime = delayTime || 0;
this.$root.off('mouseenter');
@@ -165,7 +195,7 @@ export default class ColorPicker extends EventMachin {
clearTimeout(this.timerCloseColorPicker);
});
- this.$root.on('mouseleave', () => {
+ this.$root.on('mouseleave', () => {
clearTimeout(this.timerCloseColorPicker);
this.timerCloseColorPicker = setTimeout(this.hide.bind(this), delayTime);
});
@@ -174,34 +204,34 @@ export default class ColorPicker extends EventMachin {
this.timerCloseColorPicker = setTimeout(this.hide.bind(this), delayTime);
}
- hide () {
+ hide() {
if (this.isColorPickerShow) {
- this.destroy();
- this.$root.hide();
- this.$root.remove(); // not empty
- this.isColorPickerShow = false;
+ this.destroy();
+ this.$root.hide();
+ this.$root.remove(); // not empty
+ this.isColorPickerShow = false;
}
- }
+ }
convertRGB() {
return Color.HSVtoRGB(this.currentH, this.currentS, this.currentV);
}
-
+
convertHEX() {
return Color.format(this.convertRGB(), 'hex');
}
-
- convertHSL() {
+
+ convertHSL() {
return Color.HSVtoHSL(this.currentH, this.currentS, this.currentV);
}
- getCurrentColor () {
+ getCurrentColor() {
return this.information.getFormattedColor();
}
- getFormattedColor (format) {
+ getFormattedColor(format) {
format = format || 'hex';
-
+
if (format == 'rgb') {
var rgb = this.convertRGB();
rgb.a = this.currentA;
@@ -223,32 +253,38 @@ export default class ColorPicker extends EventMachin {
this.control.setInputColor(isNoInputColor);
this.callbackColorValue();
- }
+ }
changeInputColorAfterNextFormat() {
this.control.setInputColor();
this.callbackColorValue();
- }
+ }
+
+ callbackColorValue() {
+ if (typeof this.opt.onChange == 'function') {
+ if (!isNaN(this.currentA)) {
+ this.opt.onChange(this.getCurrentColor());
+ }
+
+ }
- callbackColorValue () {
if (typeof this.colorpickerCallback == 'function') {
-
if (!isNaN(this.currentA)) {
this.colorpickerCallback(this.getCurrentColor());
}
-
- }
+
+ }
}
-
+
caculateHSV() {
var obj = this.palette.caculateSV();
var control = this.control.caculateH();
var s = obj.s;
- var v = obj.v;
- var h = control.h ;
+ var v = obj.v;
+ var h = control.h;
if (obj.width == 0) {
@@ -263,70 +299,70 @@ export default class ColorPicker extends EventMachin {
}
- setColorUI() {
+ setColorUI() {
this.control.setColorUI()
this.palette.setColorUI()
}
- setCurrentHSV (h, s, v, a) {
+ setCurrentHSV(h, s, v, a) {
this.currentA = a;
this.currentH = h;
this.currentS = s;
this.currentV = v;
- }
-
+ }
+
- setCurrentH (h) {
+ setCurrentH(h) {
this.currentH = h;
}
- setCurrentA ( a) {
+ setCurrentA(a) {
this.currentA = a;
}
- setBackgroundColor (color) {
+ setBackgroundColor(color) {
this.palette.setBackgroundColor(color);
}
- setCurrentFormat (format) {
- this.format = format;
+ setCurrentFormat(format) {
+ this.format = format;
this.information.setCurrentFormat(format);
}
- getHSV (colorObj) {
+ getHSV(colorObj) {
if (colorObj.type == 'hsl') {
return Color.HSLtoHSV(colorObj.h, colorObj.s, colorObj.l);
} else {
return Color.RGBtoHSV(colorObj);
- }
+ }
}
initColor(newColor, format) {
let c = newColor || "#FF0000", colorObj = Color.parse(c);
format = format || colorObj.type;
-
+
this.setCurrentFormat(format);
let hsv = this.getHSV(colorObj);
this.setCurrentHSV(hsv.h, hsv.s, hsv.v, colorObj.a);
this.setColorUI();
this.setHueColor();
- this.setInputColor();
- }
+ this.setInputColor();
+ }
changeInformationColor(newColor) {
let c = newColor || "#FF0000", colorObj = Color.parse(c);
-
+
let hsv = this.getHSV(colorObj);
this.setCurrentHSV(hsv.h, hsv.s, hsv.v, colorObj.a);
this.setColorUI();
this.setHueColor();
this.control.setInputColor();
this.callbackColorValue();
- }
+ }
- setHueColor () {
+ setHueColor() {
this.control.setOnlyHueColor();
}
@@ -335,25 +371,25 @@ export default class ColorPicker extends EventMachin {
var hasColorPicker = new Dom(el).closest('codemirror-colorpicker');
var hasCodeMirror = new Dom(el).closest('CodeMirror');
var IsInHtml = el.nodeName == 'HTML';
-
+
return !!(hasColorPicker || hasColorView || hasCodeMirror);
}
-
- checkInHtml (el) {
+
+ checkInHtml(el) {
var IsInHtml = el.nodeName == 'HTML';
-
+
return IsInHtml;
- }
+ }
// Event Bindings
'mouseup document' (e) {
this.palette.EventDocumentMouseUp(e);
this.control.EventDocumentMouseUp(e);
-
+
// when color picker clicked in outside
if (this.checkInHtml(e.target)) {
//this.setHideDelay(hideDelay);
- } else if (this.checkColorPickerClass(e.target) == false ) {
+ } else if (this.checkColorPickerClass(e.target) == false) {
this.hide();
}
}
@@ -361,26 +397,26 @@ export default class ColorPicker extends EventMachin {
'mousemove document' (e) {
this.palette.EventDocumentMouseMove(e);
this.control.EventDocumentMouseMove(e);
- }
+ }
- initializeEvent () {
+ initializeEvent() {
this.initializeEventMachin();
this.palette.initializeEvent();
this.control.initializeEvent();
this.information.initializeEvent()
- this.currentColorSets.initializeEvent()
+ this.currentColorSets.initializeEvent()
this.colorSetsChooser.initializeEvent();
this.contextMenu.initializeEvent();
-
+
}
- currentFormat () {
+ currentFormat() {
this.information.currentFormat();
}
- toggleColorChooser () {
+ toggleColorChooser() {
this.colorSetsChooser.toggle();
}
@@ -388,18 +424,18 @@ export default class ColorPicker extends EventMachin {
this.colorSetsChooser.refresh();
}
- getColorSetsList () {
+ getColorSetsList() {
return this.colorSetsList.getColorSetsList();
}
- setCurrentColorSets (nameOrIndex) {
+ setCurrentColorSets(nameOrIndex) {
this.colorSetsList.setCurrentColorSets(nameOrIndex);
this.currentColorSets.refresh();
}
- setColorSets (list) {
+ setColorSets(list) {
this.colorSetsList.setUserList(list);
- }
+ }
destroy() {
super.destroy();
diff --git a/src/colorpicker/type/ChromeDevtool/ChromeColorControl.js b/src/colorpicker/type/ChromeDevtool/ChromeColorControl.js
deleted file mode 100644
index e0edf2b..0000000
--- a/src/colorpicker/type/ChromeDevtool/ChromeColorControl.js
+++ /dev/null
@@ -1,257 +0,0 @@
-
-import Color from '../../../util/Color'
-import HueColor from '../../../util/HueColor'
-import Dom from '../../../util/Dom'
-import Event from '../../../util/Event'
-import EventMachin from '../../../util/EventMachin'
-
-
-export default class ChromeColorControl extends EventMachin {
- constructor (colorpicker) {
- super();
- this.colorpicker = colorpicker;
- this.initialize();
- }
-
- initialize () {
- this.$el = new Dom('div', 'control' );
- this.$hue = this.$el.createChild('div', 'hue' );
- this.$opacity = this.$el.createChild('div', 'opacity' );
- this.$controlPattern = this.$el.createChild('div', 'empty' );
- this.$controlColor = this.$el.createChild('div', 'color' );
-
- this.$hueContainer = this.$hue.createChild('div', 'hue-container' );
- this.$drag_bar = this.$hueContainer.createChild('div', 'drag-bar');
- this.drag_bar_pos = {}
-
- this.$opacityContainer = this.$opacity.createChild('div', 'opacity-container' );
- this.$opacityColorBar = this.$opacityContainer.createChild('div', 'color-bar' );
-
- this.$opacity_drag_bar = this.$opacityContainer.createChild('div', 'drag-bar2' );
- this.opacity_drag_bar_pos = {}
- }
-
- setBackgroundColor (color) {
- this.$controlColor.css("background-color", color);
- }
-
- refresh () {
- this.setColorUI();
- }
-
- setColorUI() {
- var x = this.$el.width() * this.colorpicker.currentS,
- y = this.$el.height() * ( 1 - this.colorpicker.currentV );
-
- this.$drag_pointer.css({
- left : (x - 5) + "px",
- top : (y - 5) + "px"
- });
- }
-
-
- setMainColor(e) {
- e.preventDefault();
- var pos = this.colorpicker.$root.position(); // position for screen
- var w = $color.width();
- var h = $color.height();
-
- var x = e.clientX - pos.left;
- var y = e.clientY - pos.top;
-
- if (x < 0) x = 0;
- else if (x > w) x = w;
-
- if (y < 0) y = 0;
- else if (y > h) y = h;
-
- this.$drag_pointer.css({
- left: (x - 5) + 'px',
- top: (y - 5) + 'px'
- });
-
- this.colorpicker.caculateHSV()
- this.colorpicker.setInputColor();
- }
-
-
- setOpacityColorBar(hueColor) {
- var rgb = Color.parse(hueColor);
-
- rgb.a = 0;
- var start = Color.format(rgb, 'rgb');
-
- rgb.a = 1;
- var end = Color.format(rgb, 'rgb');
-
- var prefix = cssPrefix;
- this.$opacityColorBar.css('background', 'linear-gradient(to right, ' + start + ', ' + end + ')');
- }
-
- setOpacity(e) {
- var min = this.$opacityContainer.offset().left;
- var max = min + this.$opacityContainer.width();
- var current = Event.pos(e).clientX;
- var dist;
-
- if (current < min) {
- dist = 0;
- } else if (current > max) {
- dist = 100;
- } else {
- dist = (current - min) / (max - min) * 100;
- }
-
- var x = (this.$opacityContainer.width() * (dist/100));
-
- this.$opacity_drag_bar.css({
- left: (x -Math.ceil(this.$opacity_drag_bar.width()/2)) + 'px'
- });
-
- this.opacity_drag_bar_pos = { x };
-
- this.colorpicker.setCurrentA(this.caculateOpacity());
- this.colorpicker.currentFormat();
- this.colorpicker.setInputColor();
- }
-
- setInputColor () {
- this.setBackgroundColor(this.colorpicker.getFormattedColor('rgb'));
-
- var rgb = this.colorpicker.convertRGB();
- var colorString = Color.format(rgb, 'rgb');
- this.setOpacityColorBar(colorString);
- }
-
- setColorUI() {
-
- var hueX = this.$hueContainer.width() * (this.colorpicker.currentH / 360);
-
- this.$drag_bar.css({
- left : (hueX - 7.5) + 'px'
- });
-
- this.drag_bar_pos = { x : hueX };
-
- var opacityX = this.$opacityContainer.width() * (this.colorpicker.currentA || 0);
-
- this.$opacity_drag_bar.css({
- left : (opacityX - 7.5) + 'px'
- });
-
- this.opacity_drag_bar_pos = { x : opacityX };
-
- }
-
- caculateH() {
-
- var huePos = this.drag_bar_pos || { x : 0 };
-
- var h = (huePos.x / this.$hueContainer.width()) * 360;
-
- return { h } ;
- }
-
- caculateOpacity() {
- var opacityPos = this.opacity_drag_bar_pos || { x : 0 };
- var a = Math.round((opacityPos.x / this.$opacityContainer.width()) * 100) / 100;
-
- return isNaN(a) ? 1 : a;
- }
-
-
- EventDocumentMouseMove(e) {
- if (this.isHueDown) {
- this.setHueColor(e);
- }
-
- if (this.isOpacityDown) {
- this.setOpacity(e);
- }
- }
-
- EventDocumentMouseUp (e) {
- this.isHueDown = false ;
- this.isOpacityDown = false;
- }
-
- setControlColor (color) {
- this.$controlColor.css('background-color', color);
- }
-
-
- setHueColor(e) {
- var min = this.$hueContainer.offset().left;
- var max = min + this.$hueContainer.width();
- var current = e ? Event.pos(e).clientX : min + (max - min) * (this.colorpicker.currentH / 360);
-
- var dist;
- if (current < min) {
- dist = 0;
- } else if (current > max) {
- dist = 100;
- } else {
- dist = (current - min) / (max - min) * 100;
- }
-
- var x = (this.$hueContainer.width() * (dist/100));
-
- this.$drag_bar.css({
- left: (x -Math.ceil(this.$drag_bar.width()/2)) + 'px'
- });
-
- this.drag_bar_pos = { x };
-
- var hueColor = HueColor.checkHueColor(dist/100);
-
- this.colorpicker.setBackgroundColor(hueColor);
- this.colorpicker.setCurrentH((dist/100) * 360);
- this.colorpicker.setInputColor();
- }
-
- setOnlyHueColor() {
- var min = this.$hueContainer.offset().left;
- var max = min + this.$hueContainer.width();
- var current = min + (max - min) * (this.colorpicker.currentH / 360);
- var dist;
- if (current < min) {
- dist = 0;
- } else if (current > max) {
- dist = 100;
- } else {
- dist = (current - min) / (max - min) * 100;
- }
-
- var x = (this.$hueContainer.width() * (dist/100));
-
- this.$drag_bar.css({
- left: (x -Math.ceil(this.$drag_bar.width()/2)) + 'px'
- });
-
- this.drag_bar_pos = { x };
-
- var hueColor = HueColor.checkHueColor(dist/100);
- this.colorpicker.setBackgroundColor(hueColor);
- this.colorpicker.setCurrentH((dist/100) * 360);
- }
-
- 'mousedown $drag_bar' (e) {
- e.preventDefault();
- this.isHueDown = true;
- }
-
- 'mousedown $opacity_drag_bar' (e) {
- e.preventDefault();
- this.isOpacityDown = true;
- }
-
- 'mousedown $hueContainer' (e) {
- this.isHueDown = true;
- this.setHueColor(e);
- }
-
- 'mousedown $opacityContainer' (e) {
- this.isOpacityDown = true;
- this.setOpacity(e);
- }
-}
diff --git a/src/colorpicker/type/ChromeDevtool/ChromeColorInformation.js b/src/colorpicker/type/ChromeDevtool/ChromeColorInformation.js
deleted file mode 100644
index 406c925..0000000
--- a/src/colorpicker/type/ChromeDevtool/ChromeColorInformation.js
+++ /dev/null
@@ -1,281 +0,0 @@
-import Color from '../../../util/Color'
-import Dom from '../../../util/Dom'
-import Event from '../../../util/Event'
-import EventMachin from '../../../util/EventMachin'
-
-export default class ChromeColorInformation extends EventMachin {
-
- constructor(colorpicker) {
- super();
-
- this.colorpicker = colorpicker;
- this.initialize()
-
- }
-
- initialize () {
- this.$el = new Dom('div', 'information hex' );
-
- this.$informationChange = this.$el.createChild('div', 'information-change');
-
- this.$formatChangeButton = this.$informationChange.createChild('button', 'format-change-button arrow-button', { type : 'button'});
-
- this.$el.append(this.makeInputFieldHex());
- this.$el.append(this.makeInputFieldRgb());
- this.$el.append(this.makeInputFieldHsl());
-
- this.format = 'hex';
- }
-
-
- makeInputFieldHex () {
- var item = new Dom('div', 'information-item hex');
- var field = item.createChild('div', 'input-field hex');
-
- this.$hexCode = field.createChild('input', 'input', { type : 'text' });
-
- field.createChild('div', 'title').html('HEX');
-
- return item;
- }
-
- makeInputFieldRgb () {
- var item = new Dom('div', 'information-item rgb');
-
- var field = item.createChild('div', 'input-field rgb-r');
- this.$rgb_r = field.createChild('input', 'input', { type : 'number', step : 1, min : 0, max : 255 });
- field.createChild('div', 'title').html('R');
-
- field = item.createChild('div', 'input-field rgb-g');
- this.$rgb_g = field.createChild('input', 'input', { type : 'number', step : 1, min : 0, max : 255 });
- field.createChild('div', 'title').html('G');
-
- field = item.createChild('div', 'input-field rgb-b');
- this.$rgb_b = field.createChild('input', 'input', { type : 'number', step : 1, min : 0, max : 255 });
- field.createChild('div', 'title').html('B');
-
- // rgba
- field = item.createChild('div', 'input-field rgb-a');
- this.$rgb_a = field.createChild('input', 'input', { type : 'number', step : 0.01, min : 0, max : 1 });
- field.createChild('div', 'title').html('A');
-
- return item;
- }
-
- makeInputFieldHsl () {
- var item = new Dom('div', 'information-item hsl');
-
- var field = item.createChild('div', 'input-field hsl-h');
- this.$hsl_h = field.createChild('input', 'input', { type : 'number', step : 1, min : 0, max : 360 });
- field.createChild('div', 'title').html('H');
-
- field = item.createChild('div', 'input-field hsl-s');
- this.$hsl_s = field.createChild('input', 'input', { type : 'number', step: 1, min: 0, max : 100 });
- field.createChild('div', 'postfix').html('%');
- field.createChild('div', 'title').html('S');
-
- field = item.createChild('div', 'input-field hsl-l');
- this.$hsl_l = field.createChild('input', 'input', { type : 'number', step: 1, min: 0, max : 100 });
- field.createChild('div', 'postfix').html('%');
- field.createChild('div', 'title').html('L');
-
- // rgba
- field = item.createChild('div', 'input-field hsl-a');
- this.$hsl_a = field.createChild('input', 'input', { type : 'number', step : 0.01, min : 0, max : 1 });
- field.createChild('div', 'title').html('A');
-
- return item;
- }
-
- currentFormat () {
- var current_format = this.format || 'hex';
- if (this.colorpicker.currentA < 1 && current_format == 'hex' ) {
- var next_format = 'rgb';
- this.$el.removeClass(current_format);
- this.$el.addClass(next_format);
- this.format = next_format;
-
- this.colorpicker.setInputColor();
- }
- }
-
- setCurrentFormat (format) {
- this.format = format
- this.initFormat();
- }
-
- initFormat () {
- var current_format = this.format || 'hex';
-
- this.$el.removeClass('hex');
- this.$el.removeClass('rgb');
- this.$el.removeClass('hsl');
- this.$el.addClass(current_format);
- }
-
- nextFormat() {
- var current_format = this.format || 'hex';
-
- var next_format = 'hex';
- if (current_format == 'hex') {
- next_format = 'rgb';
- } else if (current_format == 'rgb') {
- next_format = 'hsl';
- } else if (current_format == 'hsl') {
- if (this.colorpicker.currentA == 1) {
- next_format = 'hex';
- } else {
- next_format = 'rgb';
- }
- }
-
- this.$el.removeClass(current_format);
- this.$el.addClass(next_format);
- this.format = next_format;
-
- this.setInputColor();
- this.colorpicker.changeInputColorAfterNextFormat();
- }
-
-
-
- setRGBInput(r, g, b) {
- this.$rgb_r.val(r);
- this.$rgb_g.val(g);
- this.$rgb_b.val(b);
- this.$rgb_a.val(this.colorpicker.currentA);
- }
-
- setHSLInput(h, s, l) {
- this.$hsl_h.val(h);
- this.$hsl_s.val(s);
- this.$hsl_l.val(l);
- this.$hsl_a.val(this.colorpicker.currentA);
- }
-
- getHexFormat() {
- return Color.format({
- r : this.$rgb_r.int(),
- g : this.$rgb_g.int(),
- b : this.$rgb_b.int()
- }, 'hex');
- }
-
- getRgbFormat() {
- return Color.format({
- r : this.$rgb_r.int(),
- g : this.$rgb_g.int(),
- b : this.$rgb_b.int(),
- a : this.$rgb_a.float()
- }, 'rgb');
- }
-
- getHslFormat() {
- return Color.format({
- h : this.$hsl_h.val(),
- s : this.$hsl_s.val(),
- l : this.$hsl_l.val(),
- a : this.$hsl_a.float()
- }, 'hsl');
- }
-
-
- convertRGB() {
- return this.colorpicker.convertRGB();
- }
-
- convertHEX() {
- return this.colorpicker.convertHEX();
- }
-
- convertHSL() {
- return this.colorpicker.convertHSL();
- }
-
- getFormattedColor (format, fixed = false) {
- format = format || this.getFormat();
- if (format == 'hex') {
- return this.$hexCode.val();
- } else if (format == 'rgb') {
- return this.getRgbFormat(fixed);
- } else if (format == 'hsl') {
- return this.getHslFormat(fixed);
- }
- }
-
- getFormat () {
- return this.format || 'hex';
- }
-
- setInputColor() {
- var format = this.getFormat();
-
- var rgb = null;
- if (format == 'hex') {
- this.$hexCode.val(this.convertHEX());
- } else if (format == 'rgb') {
- var rgb = this.convertRGB();
- this.setRGBInput(rgb.r, rgb.g, rgb.b, rgb.a);
- } else if (format == 'hsl') {
- var hsl = this.convertHSL();
- this.setHSLInput(hsl.h, hsl.s, hsl.l, hsl.a);
- }
- }
-
-
- checkNumberKey(e) {
- return Event.checkNumberKey(e);
- }
-
- checkNotNumberKey(e) {
- return !Event.checkNumberKey(e);
- }
-
- //'keydown.checkNotNumberKey $rgb_r' (e) { e.preventDefault(); }
- //'keydown.checkNotNumberKey $rgb_g' (e) { e.preventDefault(); }
- //'keydown.checkNotNumberKey $rgb_b' (e) { e.preventDefault(); }
-
- //'keydown.checkNumberKey $rgb_r' (e) { this.setRGBtoHexColor(e); }
- //'keydown.checkNumberKey $rgb_g' (e) { this.setRGBtoHexColor(e); }
- //'keydown.checkNumberKey $rgb_b' (e) { this.setRGBtoHexColor(e); }
-
- changeRgbColor () {
- this.colorpicker.changeInformationColor(this.getRgbFormat());
- }
-
- changeHslColor () {
- this.colorpicker.changeInformationColor(this.getHslFormat());
- }
-
- 'change $rgb_r' (e) { this.changeRgbColor(); }
- 'change $rgb_g' (e) { this.changeRgbColor(); }
- 'change $rgb_b' (e) { this.changeRgbColor(); }
- 'change $rgb_a' (e) { this.changeRgbColor(); }
-
- 'change $hsl_h' (e) { this.changeHslColor(); }
- 'change $hsl_s' (e) { this.changeHslColor(); }
- 'change $hsl_l' (e) { this.changeHslColor(); }
- 'change $hsl_a' (e) { this.changeHslColor(); }
-
- 'keydown $hexCode' (e) {
- if(e.which < 65 || e.which > 70) {
- return this.checkNumberKey(e);
- }
- }
-
- 'keyup $hexCode' (e) {
- var code = this.$hexCode.val();
-
- if(code.charAt(0) == '#' && code.length == 7) {
- this.colorpicker.changeInformationColor(code);
- }
- }
-
- 'click $formatChangeButton' (e) {
- this.nextFormat();
- }
-
- refresh () {
-
- }
-}
diff --git a/src/colorpicker/type/ChromeDevtool/ChromeColorPalette.js b/src/colorpicker/type/ChromeDevtool/ChromeColorPalette.js
deleted file mode 100644
index 12cee54..0000000
--- a/src/colorpicker/type/ChromeDevtool/ChromeColorPalette.js
+++ /dev/null
@@ -1,100 +0,0 @@
-import Color from '../../../util/Color'
-import Dom from '../../../util/Dom'
-import Event from '../../../util/Event'
-import EventMachin from '../../../util/EventMachin'
-
-export default class ChromeColorPallet extends EventMachin {
- constructor (colorpicker) {
- super();
-
- this.colorpicker = colorpicker;
- this.initialize();
- }
-
- initialize () {
- this.$el = new Dom('div', 'color');
- this.$saturation = this.$el.createChild('div', 'saturation' );
- this.$value = this.$saturation.createChild('div', 'value' );
- this.$drag_pointer = this.$value.createChild('div', 'drag-pointer' );
- }
-
- setBackgroundColor (color) {
- this.$el.css("background-color", color);
- }
-
- refresh () {
- this.setColorUI();
- }
-
- caculateSV () {
- var pos = this.drag_pointer_pos || { x : 0, y : 0 };
-
- var width = this.$el.width();
- var height = this.$el.height();
-
- var s = (pos.x / width);
- var v = ((height - pos.y) / height);
-
- return { s , v, width, height }
- }
-
- setColorUI() {
- var x = this.$el.width() * this.colorpicker.currentS, y = this.$el.height() * ( 1 - this.colorpicker.currentV );
-
- this.$drag_pointer.css({
- left : (x - 5) + "px",
- top : (y - 5) + "px"
- });
-
- this.drag_pointer_pos = { x , y };
- }
-
-
- setMainColor(e) {
- e.preventDefault();
- var pos = this.$el.position();
- var w = this.$el.width();
- var h = this.$el.height();
-
- var x = e.clientX - pos.left;
- var y = e.clientY - pos.top;
-
- if (x < 0) x = 0;
- else if (x > w) x = w;
-
- if (y < 0) y = 0;
- else if (y > h) y = h;
-
- this.$drag_pointer.css({
- left: (x - 5) + 'px',
- top: (y - 5) + 'px'
- });
-
- this.drag_pointer_pos = { x , y }
-
- this.colorpicker.caculateHSV()
- this.colorpicker.setInputColor();
- }
-
-
- EventDocumentMouseUp (e) {
- this.isDown = false;
- }
-
- EventDocumentMouseMove(e) {
- if (this.isDown) {
- this.setMainColor(e);
- }
- }
-
-
- mousedown (e) {
- this.isDown = true;
- this.setMainColor(e);
- }
-
- mouseup (e) {
- this.isDown = false;
- }
-
-}
diff --git a/src/colorpicker/type/ChromeDevtool/ChromeColorSetsChooser.js b/src/colorpicker/type/ChromeDevtool/ChromeColorSetsChooser.js
deleted file mode 100644
index 26348c6..0000000
--- a/src/colorpicker/type/ChromeDevtool/ChromeColorSetsChooser.js
+++ /dev/null
@@ -1,109 +0,0 @@
-import Color from '../../../util/Color'
-import Dom from '../../../util/Dom'
-import Event from '../../../util/Event'
-import EventMachin from '../../../util/EventMachin'
-
-const DATA_COLORSETS_INDEX = 'data-colorsets-index';
-
-export default class ChromeColorSetsChooser extends EventMachin {
- constructor (colorpicker) {
- super();
-
- this.colorpicker = colorpicker;
-
- this.initialize();
- }
-
- initialize () {
- // make colorset-chooser
- this.$el = new Dom('div', 'color-chooser' );
-
- const $container = this.$el.createChild('div', 'color-chooser-container');
-
- const $header = $container.createChild('div', 'colorsets-item colorsets-item-header');
-
- $header.createChild('h1', 'title').html('Color Paletts')
-
- this.$toggleButton = $header.createChild('span', 'items').html('×');
-
- this.$colorsetsList = $container.createChild('div', 'colorsets-list' );
-
- this.refresh();
- }
-
- refresh () {
- this.$colorsetsList.html(this.makeColorSetsList());
- }
-
- makeColorItemList (colors, maxCount = 5) {
- var $list = new Dom('div');
-
- for(var i = 0; i < maxCount; i++) {
- var color = colors[i] || 'rgba(255, 255, 255, 1)';
- var $item = $list.createChild('div', 'color-item', {
- title: color
- });
-
- $item.createChild('div', 'color-view', null, {
- 'background-color': color
- });
- }
-
- return $list;
- }
-
- makeColorSetsList () {
- const $div = new Dom('div');
-
- // colorsets
- const colorSets = this.colorpicker.getColorSetsList();
- colorSets.forEach( (element, index) => {
- const $item = $div.createChild('div', 'colorsets-item', {
- [DATA_COLORSETS_INDEX] : index
- });
-
- $item.createChild('h1', 'title').html(element.name)
-
- $item.createChild('div', 'items').append(this.makeColorItemList(element.colors, 5))
-
- });
-
- return $div;
- }
-
- show () {
- this.$el.addClass('open');
- }
-
- hide () {
- this.$el.removeClass('open');
- }
-
- toggle () {
- this.$el.toggleClass('open');
- }
-
-
- 'click $toggleButton' (e) {
- this.toggle();
- }
-
- 'click $colorsetsList' (e) {
- e.preventDefault();
- const $item = new Dom(e.target).closest('colorsets-item');
-
- if ($item) {
-
- const index = parseInt($item.attr(DATA_COLORSETS_INDEX));
- this.colorpicker.setCurrentColorSets(index);
- this.hide();
- }
- }
-
- destroy () {
- super.destroy();
-
- this.hide();
- }
-
-}
diff --git a/src/colorpicker/type/ChromeDevtool/ChromeColorSetsList.js b/src/colorpicker/type/ChromeDevtool/ChromeColorSetsList.js
deleted file mode 100644
index a57ab0f..0000000
--- a/src/colorpicker/type/ChromeDevtool/ChromeColorSetsList.js
+++ /dev/null
@@ -1,129 +0,0 @@
-import Color from '../../../util/Color'
-
-let colorSetsList = [
- {
- name : "Material",
- colors: [
- '#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#2196F3', '#03A9F4', '#00BCD4', '#009688', '#4CAF50', '#8BC34A', '#CDDC39', '#FFEB3B', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B'
- ]
- },
- {
- name : "Custom", "edit" : true, "colors" : []
- },
- {
- name: "Color Scale", "scale" : ['red', 'yellow', 'black' ], count : 5
- }
-]
-
-
-
-export default class ChromeColorSetsList {
- constructor (colorpicker) {
- this.colorpicker = colorpicker;
-
- this.setUserList(this.colorpicker.getOption('colorSets'));
- }
-
- list () {
- return this.userList || colorSetsList;
- }
-
- setUserList (list) {
- this.userList = list;
-
- this.resetUserList();
-
- this.setCurrentColorSets();
- }
-
- resetUserList () {
- if (this.userList && this.userList.length) {
- this.userList = this.userList.map( (element, index) => {
-
- if (typeof element.colors == 'function') {
- const makeCallback = element.colors;
-
- element.colors = makeCallback(this.colorpicker, this);
- element._colors = makeCallback;
- }
-
- return Object.assign({
- name: `color-${index}`,
- colors : []
- }, element)
- })
- }
- }
-
- setCurrentColorSets (nameOrIndex) {
-
- const _list = this.list();
-
- if (typeof nameOrIndex == 'undefined') {
- this.currentColorSets = _list[0];
- } else if (typeof nameOrIndex == 'number') {
- this.currentColorSets = _list[nameOrIndex];
- } else {
- this.currentColorSets = _list.filter(function (obj) {
- return obj.name == nameOrIndex;
- })[0];
- }
-
-
- }
-
- getCurrentColorSets () {
- return this.currentColorSets;
- }
-
- addCurrentColor ( color) {
- if (Array.isArray(this.currentColorSets.colors)) {
- this.currentColorSets.colors.push(color);
- }
- }
-
- removeCurrentColor (index) {
- if (this.currentColorSets.colors[index]) {
- this.currentColorSets.colors.splice(index, 1);
- }
- }
-
- removeCurrentColorToTheRight (index) {
- if (this.currentColorSets.colors[index]) {
- this.currentColorSets.colors.splice(index, Number.MAX_VALUE);
- }
- }
-
- clearPalette () {
- if (this.currentColorSets.colors) {
- this.currentColorSets.colors = [];
- }
- }
-
- getCurrentColors ( ) {
- return this.getColors(this.currentColorSets);
- }
-
- getColors (element) {
-
- if (element.scale) {
- return Color.scale(element.scale, element.count);
- }
-
- return element.colors || [];
- }
-
- getColorSetsList () {
- return this.list().map(element => {
- return {
- name : element.name,
- colors : this.getColors(element)
- }
- });
- }
-
-
- destroy () {
-
- }
-}
\ No newline at end of file
diff --git a/src/colorpicker/type/ChromeDevtool/ChromeCurrentColorSets.js b/src/colorpicker/type/ChromeDevtool/ChromeCurrentColorSets.js
deleted file mode 100644
index ea18c18..0000000
--- a/src/colorpicker/type/ChromeDevtool/ChromeCurrentColorSets.js
+++ /dev/null
@@ -1,123 +0,0 @@
-import Color from '../../../util/Color'
-import Dom from '../../../util/Dom'
-import Event from '../../../util/Event'
-import EventMachin from '../../../util/EventMachin'
-
-export default class ChromeCurrentColorSets extends EventMachin {
- constructor (colorpicker) {
- super();
-
- this.colorpicker = colorpicker;
-
- this.colorSetsList = this.colorpicker.colorSetsList;
-
- this.initialize();
- }
-
- makeCurrentColorSets () {
- var list = new Dom('div', 'current-color-sets');
- const currentColorSets = this.colorSetsList.getCurrentColorSets()
- const colors = this.colorSetsList.getCurrentColors()
-
-
- for(var i = 0, len = colors.length; i < len; i++) {
- var color = colors[i];
- var item = list.createChild('div', 'color-item', {
- 'title' : color,
- 'data-index' : i,
- 'data-color' : color
- });
-
- item.createChild('div', 'empty');
- item.createChild('div', 'color-view', null, {
- 'background-color': color
- })
- }
-
-
- if (currentColorSets.edit) {
- list.createChild('div', 'add-color-item').html('+');
- }
-
- return list;
- }
-
- initialize () {
- // make colorsets view
- this.$el = new Dom('div', 'colorsets' );
-
- const $colorSetsMenu = this.$el.createChild('div', 'menu', {
- title: 'Open Color Pallets'
- });
- this.$colorSetsColorList = this.$el.createChild('div', 'color-list' );
-
- this.$colorSetsChooseButton = $colorSetsMenu.createChild('button', 'color-sets-choose-btn arrow-button', {
- type : 'button'
- });
-
- this.refresh();
- }
-
- refresh () {
- this.$colorSetsColorList.html(this.makeCurrentColorSets())
- }
-
- refreshAll () {
- this.refresh();
- this.colorpicker.refreshColorSetsChooser();
- }
-
- addColor (color) {
- this.colorSetsList.addCurrentColor(color);
- this.refreshAll();
- }
-
- removeColor (index) {
- this.colorSetsList.removeCurrentColor(index);
- this.refreshAll();
- }
-
- removeAllToTheRight (index) {
- this.colorSetsList.removeCurrentColorToTheRight(index);
- this.refreshAll();
- }
-
- clearPalette () {
- this.colorSetsList.clearPalette();
- this.refreshAll();
- }
-
- 'click $colorSetsChooseButton' (e) {
- this.colorpicker.toggleColorChooser();
- }
-
- 'contextmenu $colorSetsColorList' (e) {
- e.preventDefault();
- const currentColorSets = this.colorSetsList.getCurrentColorSets()
-
- if (!currentColorSets.edit) {
- return;
- }
-
- const $target = new Dom(e.target);
-
- const $item = $target.closest('color-item');
-
- if ($item) {
- const index = parseInt($item.attr('data-index'));
-
- this.colorpicker.showContextMenu(e, index);
- } else {
- this.colorpicker.showContextMenu(e);
- }
- }
-
- 'click $colorSetsColorList .add-color-item' (e) {
- this.addColor(this.colorpicker.getCurrentColor());
- }
-
- 'click $colorSetsColorList .color-item' (e) {
- this.colorpicker.setColor(e.$delegateTarget.attr('data-color'));
- }
-
-}
diff --git a/src/colorpicker/type/ChromeDevtool/ChromeCurrentColorSetsContextMenu.js b/src/colorpicker/type/ChromeDevtool/ChromeCurrentColorSetsContextMenu.js
deleted file mode 100644
index 0b9c573..0000000
--- a/src/colorpicker/type/ChromeDevtool/ChromeCurrentColorSetsContextMenu.js
+++ /dev/null
@@ -1,77 +0,0 @@
-import Color from '../../../util/Color'
-import Dom from '../../../util/Dom'
-import Event from '../../../util/Event'
-import EventMachin from '../../../util/EventMachin'
-
-export default class ChromeCurrentColorSetsContextMenu extends EventMachin {
- constructor (colorpicker) {
- super();
-
- this.colorpicker = colorpicker;
- this.currentColorSets = colorpicker.currentColorSets;
-
- this.initialize();
- }
-
- initialize () {
- // make colorsets view
- this.$el = new Dom('ul', 'colorsets-contextmenu' );
-
- this.$el.createChild('li', 'menu-item small-hide', {
- 'data-type' : 'remove-color'
- }).html('Remove color')
-
- this.$el.createChild('li', 'menu-item small-hide', {
- 'data-type' : 'remove-all-to-the-right'
- }).html('Remove all to the right')
-
- this.$el.createChild('li', 'menu-item', {
- 'data-type' : 'clear-palette'
- }).html('Clear palette')
-
- }
-
- show (e, index) {
- const $event = Event.pos(e);
-
- this.$el.css({
- top: ($event.clientY - 10) + 'px',
- left: $event.clientX + 'px'
- });
- this.$el.addClass('show');
- this.selectedColorIndex = index;
-
- if (typeof this.selectedColorIndex == 'undefined') {
- this.$el.addClass('small')
- } else {
- this.$el.removeClass('small')
- }
-
- }
-
- hide () {
- this.$el.removeClass('show');
- }
-
- runCommand (command) {
- switch(command) {
- case 'remove-color':
- this.currentColorSets.removeColor(this.selectedColorIndex);
- break;
- case 'remove-all-to-the-right':
- this.currentColorSets.removeAllToTheRight(this.selectedColorIndex);
- break;
- case 'clear-palette':
- this.currentColorSets.clearPalette();
- break;
- }
- }
-
- 'click $el .menu-item' (e) {
- e.preventDefault();
-
- this.runCommand(e.$delegateTarget.attr('data-type'));
- this.hide();
- }
-
-}
diff --git a/src/colorpicker/type/ChromeDevtool/index.js b/src/colorpicker/type/ChromeDevtool/index.js
deleted file mode 100644
index 654b046..0000000
--- a/src/colorpicker/type/ChromeDevtool/index.js
+++ /dev/null
@@ -1,319 +0,0 @@
-import Color from '../../../util/Color'
-import Dom from '../../../util/Dom'
-import Event from '../../../util/Event'
-import EventMachin from '../../../util/EventMachin'
-
-import ColorControl from './ChromeColorControl'
-import ColorInformation from './ChromeColorInformation'
-import ColorPalette from './ChromeColorPalette'
-import ColorSetsChooser from './ChromeColorSetsChooser'
-import ColorSetsList from './ChromeColorSetsList'
-import CurrentColorSets from './ChromeCurrentColorSets'
-import CurrentColorSetsContextMenu from './ChromeCurrentColorSetsContextMenu'
-
-export default class ChromeDevtool extends EventMachin {
- constructor (opt) {
- super();
-
- this.opt = opt || {};
- this.$root = null;
- this.format = 'rgb';
- this.currentA = 0;
- this.currentH = 0;
- this.currentS = 0;
- this.currentV = 0;
- this.colorSetsList = new ColorSetsList(this);
- this.colorpickerCallback = this.opt.onChange || (function () {});
-
- this.control = new ColorControl(this);
- this.palette = new ColorPalette(this);
- this.information = new ColorInformation(this);
- this.colorSetsChooser = new ColorSetsChooser(this);
- this.currentColorSets = new CurrentColorSets(this);
- this.contextMenu = new CurrentColorSetsContextMenu(this, this.currentColorSets);
-
- this.initialize();
- }
-
- getOption (key) {
- return this.opt[key];
- }
-
- initialize () {
- this.$root = new Dom('div', 'codemirror-colorpicker');
-
- this.$root.append(this.palette.$el);
- this.$root.append(this.control.$el);
- this.$root.append(this.information.$el);
- this.$root.append(this.currentColorSets.$el);
- this.$root.append(this.colorSetsChooser.$el);
- this.$root.append(this.contextMenu.$el);
-
- if (this.opt.target) {
- this.$root.appendTo(this.opt.target);
- }
-
-
- this.$checkColorPickerClass = this.checkColorPickerClass.bind(this);
-
- this.initializeEvent();
-
- this.initColor(this.opt.color);
- }
-
- showContextMenu (e, index) {
- this.contextMenu.show(e, index);
- }
-
- setColor(value) {
- if(typeof(value) == "object") {
- if(!value.r || !value.g || !value.b)
- return;
-
- this.initColor(Color.format(value, "hex"));
- } else if(typeof(value) == "string") {
- this.initColor(value);
- }
- }
-
- getColor(type) {
- this.caculateHSV();
- var rgb = this.convertRGB();
-
- if (type) {
- return Color.format(rgb, type);
- }
-
- return rgb;
- }
-
- definePositionForArrow (opt, elementScreenLeft, elementScreenTop) {
- //this.$arrow.css({})
- }
-
- convertRGB() {
- return Color.HSVtoRGB(this.currentH, this.currentS, this.currentV);
- }
-
- convertHEX() {
- return Color.format(this.convertRGB(), 'hex');
- }
-
- convertHSL() {
- return Color.HSVtoHSL(this.currentH, this.currentS, this.currentV);
- }
-
- getCurrentColor () {
- return this.information.getFormattedColor();
- }
-
- getFormattedColor (format) {
- format = format || 'hex';
-
- if (format == 'rgb') {
- var rgb = this.convertRGB();
- rgb.a = this.currentA;
- return Color.format(rgb, 'rgb');
- } else if (format == 'hsl') {
- var hsl = this.convertHSL();
- hsl.a = this.currentA;
- return Color.format(hsl, 'hsl');
- } else {
- var rgb = this.convertRGB();
- return Color.format(rgb, 'hex');
- }
- }
-
-
-
- setInputColor(isNoInputColor) {
- this.information.setInputColor(isNoInputColor);
- this.control.setInputColor(isNoInputColor);
-
- this.callbackColorValue();
- }
-
- changeInputColorAfterNextFormat() {
- this.control.setInputColor();
-
- this.callbackColorValue();
- }
-
- callbackColorValue () {
- if (typeof this.colorpickerCallback == 'function') {
-
- if (!isNaN(this.currentA)) {
- this.colorpickerCallback(this.getCurrentColor());
- }
-
- }
- }
-
- caculateHSV() {
-
- var obj = this.palette.caculateSV();
- var control = this.control.caculateH();
-
- var s = obj.s;
- var v = obj.v;
- var h = control.h ;
-
-
- if (obj.width == 0) {
- h = 0;
- s = 0;
- v = 0;
- }
-
- this.currentH = h;
- this.currentS = s;
- this.currentV = v;
- }
-
-
- setColorUI() {
- this.control.setColorUI()
- this.palette.setColorUI()
- }
-
- setCurrentHSV (h, s, v, a) {
- this.currentA = a;
- this.currentH = h;
- this.currentS = s;
- this.currentV = v;
- }
-
-
- setCurrentH (h) {
- this.currentH = h;
- }
-
- setCurrentA ( a) {
- this.currentA = a;
- }
-
- setBackgroundColor (color) {
- this.palette.setBackgroundColor(color);
- }
-
- setCurrentFormat (format) {
- this.format = format;
- this.information.setCurrentFormat(format);
- }
-
- getHSV (colorObj) {
- if (colorObj.type == 'hsl') {
- return Color.HSLtoHSV(colorObj.h, colorObj.s, colorObj.l);
- } else {
- return Color.RGBtoHSV(colorObj);
- }
-
- }
-
- initColor(newColor, format) {
- let c = newColor || "#FF0000", colorObj = Color.parse(c);
- format = format || colorObj.type;
-
- this.setCurrentFormat(format);
-
- let hsv = this.getHSV(colorObj);
- this.setCurrentHSV(hsv.h, hsv.s, hsv.v, colorObj.a);
- this.setColorUI();
- this.setHueColor();
- this.setInputColor();
- }
-
- changeInformationColor(newColor) {
- let c = newColor || "#FF0000", colorObj = Color.parse(c);
-
- let hsv = this.getHSV(colorObj);
- this.setCurrentHSV(hsv.h, hsv.s, hsv.v, colorObj.a);
- this.setColorUI();
- this.setHueColor();
- this.control.setInputColor();
- this.callbackColorValue();
- }
-
- setHueColor () {
- this.control.setOnlyHueColor();
- }
-
- checkColorPickerClass(el) {
- var hasColorView = new Dom(el).closest('codemirror-colorview');
- var hasColorPicker = new Dom(el).closest('codemirror-colorpicker');
- var hasCodeMirror = new Dom(el).closest('CodeMirror');
- var IsInHtml = el.nodeName == 'HTML';
-
- return !!(hasColorPicker || hasColorView || hasCodeMirror);
- }
-
- checkInHtml (el) {
- var IsInHtml = el.nodeName == 'HTML';
-
- return IsInHtml;
- }
-
- // Event Bindings
- 'mouseup document' (e) {
- this.palette.EventDocumentMouseUp(e);
- this.control.EventDocumentMouseUp(e);
- }
-
- 'mousemove document' (e) {
- this.palette.EventDocumentMouseMove(e);
- this.control.EventDocumentMouseMove(e);
- }
-
- initializeEvent () {
-
- this.initializeEventMachin();
-
- this.palette.initializeEvent();
- this.control.initializeEvent();
- this.information.initializeEvent()
- this.currentColorSets.initializeEvent()
- this.colorSetsChooser.initializeEvent();
- this.contextMenu.initializeEvent();
-
- }
-
- currentFormat () {
- this.information.currentFormat();
- }
-
- toggleColorChooser () {
- this.colorSetsChooser.toggle();
- }
-
- refreshColorSetsChooser() {
- this.colorSetsChooser.refresh();
- }
-
- getColorSetsList () {
- return this.colorSetsList.getColorSetsList();
- }
-
- setCurrentColorSets (nameOrIndex) {
- this.colorSetsList.setCurrentColorSets(nameOrIndex);
- this.currentColorSets.refresh();
- }
-
- setColorSets (list) {
- this.colorSetsList.setUserList(list);
- }
-
- destroy() {
- super.destroy();
-
- this.control.destroy();
- this.palette.destroy();
- this.information.destroy();
- this.colorSetsChooser.destroy();
- this.colorSetsList.destroy();
- this.currentColorSets.destroy();
- this.contextMenu.destroy();
-
- // remove color picker callback
- this.colorpickerCallback = undefined;
- }
-}
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index 8332d2e..7c17936 100644
--- a/src/index.js
+++ b/src/index.js
@@ -7,8 +7,6 @@ import ColorNames from './util/ColorNames'
import ColorView from './colorview/index'
import ColorPicker from './colorpicker/index'
-import ChromeDevtool from './colorpicker/type/ChromeDevtool/index'
-
if (CodeMirror) {
CodeMirror.defineOption("colorpicker", false, function (cm, val, old) {
@@ -35,6 +33,5 @@ export default {
Color,
ColorNames,
HueColor,
- ColorPicker,
- ChromeDevtool
+ ColorPicker
}
\ No newline at end of file
diff --git a/src/scss/colorpicker.scss b/src/scss/colorpicker.scss
index a5b9afe..ad91b6e 100644
--- a/src/scss/colorpicker.scss
+++ b/src/scss/colorpicker.scss
@@ -37,12 +37,21 @@
}
}
+
@import './component/button';
@import './component/pallet';
@import './component/control';
@import './component/information';
@import './component/colorsets';
@import './component/colorchooser';
+
+ &.chromedevtool {
+
+ }
+
+ /* theme */
+ @import './themes/sketch';
+
}
@import './component/colorsets-contextmenu';
diff --git a/src/scss/index.scss b/src/scss/index.scss
index 00a75dc..a284f4f 100644
--- a/src/scss/index.scss
+++ b/src/scss/index.scss
@@ -2,4 +2,4 @@
@import './colorview';
@import './colorpicker';
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/scss/themes/sketch.scss b/src/scss/themes/sketch.scss
new file mode 100644
index 0000000..3eb7240
--- /dev/null
+++ b/src/scss/themes/sketch.scss
@@ -0,0 +1,127 @@
+&.sketch {
+ border-radius: 5px;
+
+ > .color {
+ margin: 10px 10px 2px 10px;
+ box-sizing: border-box;
+ height: 150px;
+ }
+
+ > .control {
+ padding: 0px;
+
+ > .color, > .empty {
+ position: absolute;
+ right: 10px;
+ left: auto;
+ top: 1px;
+ width: 26px;
+ height: 26px;
+ border-radius: 2px;
+ box-sizing: border-box;
+ }
+
+ > .color {
+ box-shadow: inset 0px 0px 1px 0px rgba(0, 0, 0, 0.5);
+ }
+
+ > .hue {
+ position: relative;
+ padding: 2px 2px 2px 10px;
+ margin: 0px 38px 0px 0px;
+
+ > .hue-container {
+ border-radius: 0px;
+ }
+ }
+
+ > .opacity {
+ position: relative;
+ padding: 2px 2px 2px 10px;
+ margin: 0px 38px 0px 0px;
+
+ > .opacity-container {
+ border-radius: 0px;
+ }
+ }
+
+ .drag-bar, .drag-bar2 {
+ border-radius: 0px;
+ top: 0px !important;
+ left: -2px;
+ margin-top: 1px !important;
+ width: 2px;
+ height: auto;
+ border-radius: 1px;
+ bottom: 1px !important;
+ }
+ }
+
+ > .information {
+ .information-change {
+ display: none;
+ }
+
+ &.rgb {
+ .information-item.rgb {
+ display: inherit;
+ }
+ }
+
+ &.hex {
+ .information-item.hex {
+ display: inherit;
+ }
+ }
+
+ .information-item {
+ display: inline-flex !important;
+ margin-right: 0px;
+
+ > .input-field {
+ > .title {
+ color: black;
+ font-size: 11px;
+ }
+ }
+
+ > .input-field:last-child:not(:first-child) {
+ padding-right: 0px;
+ }
+ }
+
+ .information-item.hsl {
+ display: none !important;
+ }
+
+ .information-item.hex {
+ width: 80px;
+ padding-right: 0px;
+ padding-left: 5px;
+ }
+
+ .information-item.rgb {
+ width: 140px;
+ padding-left: 0px;
+ }
+ }
+
+ > .colorsets {
+ > .menu {
+ display: none;
+ }
+
+ > .color-list {
+ margin-right: 0px;
+ padding-right: 12px;
+
+ .color-item {
+ width: 16px;
+ height: 16px;
+ border-radius: 3px;
+ margin-right: 9px;
+ margin-bottom: 10px;
+ }
+ }
+ }
+}
diff --git a/src/util/Dom.js b/src/util/Dom.js
index 6c98a67..5971829 100644
--- a/src/util/Dom.js
+++ b/src/util/Dom.js
@@ -154,6 +154,14 @@ export default class Dom {
return this;
}
+
+ cssFloat (key) {
+ return parseFloat(this.css(key));
+ }
+
+ cssInt (key) {
+ return parseInt(this.css(key));
+ }
offset () {
var rect = this.el.getBoundingClientRect();