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

Added Dynamic switching for color format #111

Merged
merged 2 commits into from
Apr 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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