Skip to content

Commit

Permalink
Add getSelectedColor function
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Aug 23, 2019
1 parent 84d8b0a commit 708b88c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ If `silent` is true (Default is false), the button won't change the current colo
* pickr.isOpen() _- Returns true if the color picker is currently open._
* pickr.getRoot()`:HTMLElement` _- Returns the root DOM-Element of the color-picker._
* pickr.getColor()`:HSVaColor` _- Returns the current HSVaColor object._
* pickr.getSelectedColor()`:HSVaColor` _- Returns the currently applied color._
* pickr.destroy() _- Destroys all functionality._
* pickr.destroyAndRemove() _- Destroys all functionality and removes the pickr element including the button._
* pickr.setColorRepresentation(type`:String`)`:Boolean` _- Change the current color-representation. Valid options are `HEX`, `RGBA`, `HSVA`, `HSLA` and `CMYK`, returns false if type was invalid._
Expand Down
2 changes: 1 addition & 1 deletion dist/pickr.es5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pickr.es5.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pickr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pickr.min.js.map

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions src/js/pickr.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ class Pickr {
// Check if color is locked
if (!options.comparison) {
_root.button.style.color = cssRGBaString;

if (!options.useAsButton) {
} else {
if (!options.useAsButton && !inst._lastColor) {
_root.preview.lastColor.style.color = cssRGBaString;
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ class Pickr {
_root.preview.lastColor
], 'click', () => {
this._emit('cancel', this);
this.setHSVA(...this._lastColor.toHSVA(), true);
this.setHSVA(...(this._lastColor || this._color).toHSVA(), true);
}),

// Save color
Expand Down Expand Up @@ -516,7 +516,7 @@ class Pickr {
this.hide();
}

this._color = null;
this._lastColor = null;
if (!this._initializingActive && !silent) {

// Fire listener
Expand Down Expand Up @@ -828,6 +828,14 @@ class Pickr {
return this._color;
}

/**
* Returns the currently selected color.
* @returns {{a, toHSVA, toHEXA, s, v, h, clone, toCMYK, toHSLA, toRGBA}}
*/
getSelectedColor() {
return this._lastColor;
}

/**
* @returns The root HTMLElement with all his components.
*/
Expand Down

0 comments on commit 708b88c

Please sign in to comment.