Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #111 from duckzland/master
Browse files Browse the repository at this point in the history
Added Dynamic switching for color format
  • Loading branch information
mjolnic committed Apr 8, 2015
2 parents 7a65c8d + 0955094 commit f1c87e3
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/js/colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
if (this.options.horizontal) {
this.picker.addClass('colorpicker-horizontal');
}
if (this.format === 'rgba' || this.format === 'hsla') {
if (this.format === 'rgba' || this.format === 'hsla' || this.options.format === false) {
this.picker.addClass('colorpicker-with-alpha');
}
if (this.options.align === 'right') {
Expand Down Expand Up @@ -429,6 +429,24 @@
if (this.currentSlider.callTop) {
this.color[this.currentSlider.callTop].call(this.color, top / this.currentSlider.maxTop);
}
// Change format dynamically
// Only occurs if user choose the dynamic format by
// setting option format to false
if (this.currentSlider.callTop == 'setAlpha'
&& this.options.format === false) {

// Converting from hex / rgb to rgba
if (this.color.value.a != 1) {
this.format = 'rgba';
this.color.origFormat = 'rgba';
}

// Converting from rgba to hex
else {
this.format = 'hex';
this.color.origFormat = 'hex';
}
}
this.update(true);

this.element.trigger({
Expand Down Expand Up @@ -462,6 +480,12 @@
} else {
var val = this.input.val();
this.color = new Color(val);
// Change format dynamically
// Only occurs if user choose the dynamic format by
// setting option format to false
if (this.color.origFormat && this.options.format === false) {
this.format = this.color.origFormat;
}
if (this.getValue(false) !== false) {
this.updateData();
this.updateComponent();
Expand Down

0 comments on commit f1c87e3

Please sign in to comment.