summaryrefslogtreecommitdiffstats
path: root/src/color.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/color.js')
-rwxr-xr-xsrc/color.js28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/color.js b/src/color.js
index e73d7e0..956693c 100755
--- a/src/color.js
+++ b/src/color.js
@@ -8,7 +8,7 @@ SVG.Color = function(color) {
this.b = 0
/* parse color */
- if (typeof color == 'string') {
+ if (typeof color === 'string') {
if (SVG.regex.isRgb.test(color)) {
/* get rgb values */
match = SVG.regex.rgb.exec(color.replace(/\s/g,''))
@@ -20,7 +20,7 @@ SVG.Color = function(color) {
} else if (SVG.regex.isHex.test(color)) {
/* get hex values */
- match = SVG.regex.hex.exec(this._fullHex(color))
+ match = SVG.regex.hex.exec(fullHex(color))
/* parse numeric values */
this.r = parseInt(match[1], 16)
@@ -29,7 +29,7 @@ SVG.Color = function(color) {
}
- } else if (typeof color == 'object') {
+ } else if (typeof color === 'object') {
this.r = color.r
this.g = color.g
this.b = color.b
@@ -46,9 +46,9 @@ SVG.extend(SVG.Color, {
// Build hex value
, toHex: function() {
return '#'
- + this._compToHex(this.r)
- + this._compToHex(this.g)
- + this._compToHex(this.b)
+ + compToHex(this.r)
+ + compToHex(this.g)
+ + compToHex(this.b)
}
// Build rgb value
, toRgb: function() {
@@ -81,23 +81,11 @@ SVG.extend(SVG.Color, {
, b: ~~(this.b + (this.destination.b - this.b) * pos)
})
}
- // Private: ensure to six-based hex
-, _fullHex: function(hex) {
- return hex.length == 4 ?
- [ '#',
- hex.substring(1, 2), hex.substring(1, 2)
- , hex.substring(2, 3), hex.substring(2, 3)
- , hex.substring(3, 4), hex.substring(3, 4)
- ].join('') : hex
- }
- // Private: component to hex value
-, _compToHex: function(comp) {
- var hex = comp.toString(16)
- return hex.length == 1 ? '0' + hex : hex
- }
})
+// Testers
+
// Test if given value is a color string
SVG.Color.test = function(color) {
color += ''