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

Commit

Permalink
transparent color support and a lot of fixes #104,#92,#89,#87,#60
Browse files Browse the repository at this point in the history
  • Loading branch information
Javi Aguilar committed Feb 18, 2015
1 parent 5f55ea5 commit a6360bd
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 155 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
ehthumbs.db
Thumbs.db
*.log
/ignore/
/ignored/
/ignore*
/node_modules/
/nbproject/
static_server.js
*.php
*.php
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bootstrap Colorpicker 2.0
# Bootstrap Colorpicker 2.1

[![Build Status](https://travis-ci.org/mjolnic/bootstrap-colorpicker.png)](https://travis-ci.org/mjolnic/bootstrap-colorpicker)

Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "mjolnic-bootstrap-colorpicker",
"version": "2.0.1",
"version": "2.1.0",
"main": [
"dist/css/bootstrap-colorpicker.css",
"dist/js/bootstrap-colorpicker.js"
],
"dependencies": {
"jquery": "^1.10",
"bootstrap": "^2"
"bootstrap": ">=2"
},
"ignore": [
"\\.*",
Expand Down
107 changes: 72 additions & 35 deletions dist/js/bootstrap-colorpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@
"white": "#ffffff",
"whitesmoke": "#f5f5f5",
"yellow": "#ffff00",
"yellowgreen": "#9acd32"
"yellowgreen": "#9acd32",
"transparent": "transparent"
},
_sanitizeNumber: function(val) {
if (typeof val === 'number') {
Expand All @@ -200,15 +201,36 @@
}
return 1;
},
isTransparent: function(strVal) {
if (!strVal) {
return false;
}
strVal = strVal.toLowerCase().trim();
return (strVal == 'transparent') || (strVal.match(/#?00000000/)) || (strVal.match(/(rgba|hsla)\(0,0,0,0?\.?0\)/));
},
rgbaIsTransparent: function(rgba) {
return ((rgba.r == 0) && (rgba.g == 0) && (rgba.b == 0) && (rgba.a == 0));
},
//parse a string to HSB
setColor: function(strVal) {
strVal = strVal.toLowerCase();
this.value = this.stringToHSB(strVal) || {
h: 0,
s: 0,
b: 0,
a: 1
};
strVal = strVal.toLowerCase().trim();
if (strVal) {
if (this.isTransparent(strVal)) {
this.value = {
h: 0,
s: 0,
b: 0,
a: 0
}
} else {
this.value = this.stringToHSB(strVal) || {
h: 0,
s: 0,
b: 0,
a: 1
}; // if parser fails, defaults to black
}
}
},
stringToHSB: function(strVal) {
strVal = strVal.toLowerCase();
Expand Down Expand Up @@ -269,6 +291,9 @@
},
toHex: function(h, s, b, a) {
var rgb = this.toRGB(h, s, b, a);
if (this.rgbaIsTransparent(rgb)) {
return 'transparent';
}
return '#' + ((1 << 24) | (parseInt(rgb.r) << 16) | (parseInt(rgb.g) << 8) | parseInt(rgb.b)).toString(16).substr(1);
},
toHSL: function(h, s, b, a) {
Expand Down Expand Up @@ -371,6 +396,9 @@
case 'rgb':
{
var rgb = this.toRGB();
if (this.rgbaIsTransparent(rgb)) {
return 'transparent';
}
return 'rgb(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ')';
}
break;
Expand Down Expand Up @@ -410,28 +438,6 @@
// from John Resig color plugin
// https://github.com/jquery/jquery-color/
stringParsers: [{
re: /#?([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
format: 'hex',
parse: function(execResult) {
return [
parseInt(execResult[1], 16),
parseInt(execResult[2], 16),
parseInt(execResult[3], 16),
1
];
}
}, {
re: /#?([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/,
format: 'hex',
parse: function(execResult) {
return [
parseInt(execResult[1] + execResult[1], 16),
parseInt(execResult[2] + execResult[2], 16),
parseInt(execResult[3] + execResult[3], 16),
1
];
}
}, {
re: /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*?\)/,
format: 'rgb',
parse: function(execResult) {
Expand Down Expand Up @@ -497,6 +503,28 @@
execResult[4]
];
}
}, {
re: /#?([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
format: 'hex',
parse: function(execResult) {
return [
parseInt(execResult[1], 16),
parseInt(execResult[2], 16),
parseInt(execResult[3], 16),
1
];
}
}, {
re: /#?([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/,
format: 'hex',
parse: function(execResult) {
return [
parseInt(execResult[1] + execResult[1], 16),
parseInt(execResult[2] + execResult[2], 16),
parseInt(execResult[3] + execResult[3], 16),
1
];
}
}, {
//predefined color name
re: /^([a-z]{3,})$/,
Expand Down Expand Up @@ -654,8 +682,6 @@
}, this));
};

Colorpicker.version = '2.0.0-beta';

Colorpicker.Color = Color;

Colorpicker.prototype = {
Expand Down Expand Up @@ -776,13 +802,14 @@
return val;
},
update: function(force) {
var val = this.updateComponent();
var val;
if ((this.getValue(false) !== false) || (force === true)) {
// Update input/data only if the current value is not blank
// Update input/data only if the current value is not empty
val = this.updateComponent();
this.updateInput(val);
this.updateData(val);
this.updatePicker(); // only update picker if value is not empty
}
this.updatePicker();
return val;

},
Expand Down Expand Up @@ -821,13 +848,23 @@
disable: function() {
if (this.hasInput()) {
this.input.prop('disabled', true);
this.element.trigger({
type: 'disable',
color: this.color,
value: this.getValue()
});
return true;
}
return false;
},
enable: function() {
if (this.hasInput()) {
this.input.prop('disabled', false);
this.element.trigger({
type: 'enable',
color: this.color,
value: this.getValue()
});
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion dist/js/bootstrap-colorpicker.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit a6360bd

Please sign in to comment.