mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-19 11:01:08 +00:00
Color.class update (#3615)
* add toHexa method with tests * Update toHexa Function (asturur)
This commit is contained in:
parent
01d8392ae3
commit
f7551924af
2 changed files with 29 additions and 5 deletions
|
|
@ -126,7 +126,7 @@
|
|||
},
|
||||
|
||||
/**
|
||||
* Returns color represenation in RGB format
|
||||
* Returns color representation in RGB format
|
||||
* @return {String} ex: rgb(0-255,0-255,0-255)
|
||||
*/
|
||||
toRgb: function() {
|
||||
|
|
@ -135,7 +135,7 @@
|
|||
},
|
||||
|
||||
/**
|
||||
* Returns color represenation in RGBA format
|
||||
* Returns color representation in RGBA format
|
||||
* @return {String} ex: rgba(0-255,0-255,0-255,0-1)
|
||||
*/
|
||||
toRgba: function() {
|
||||
|
|
@ -144,7 +144,7 @@
|
|||
},
|
||||
|
||||
/**
|
||||
* Returns color represenation in HSL format
|
||||
* Returns color representation in HSL format
|
||||
* @return {String} ex: hsl(0-360,0%-100%,0%-100%)
|
||||
*/
|
||||
toHsl: function() {
|
||||
|
|
@ -155,7 +155,7 @@
|
|||
},
|
||||
|
||||
/**
|
||||
* Returns color represenation in HSLA format
|
||||
* Returns color representation in HSLA format
|
||||
* @return {String} ex: hsla(0-360,0%-100%,0%-100%,0-1)
|
||||
*/
|
||||
toHsla: function() {
|
||||
|
|
@ -166,7 +166,7 @@
|
|||
},
|
||||
|
||||
/**
|
||||
* Returns color represenation in HEX format
|
||||
* Returns color representation in HEX format
|
||||
* @return {String} ex: FF5555
|
||||
*/
|
||||
toHex: function() {
|
||||
|
|
@ -184,6 +184,20 @@
|
|||
return r.toUpperCase() + g.toUpperCase() + b.toUpperCase();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns color representation in HEXA format
|
||||
* @return {String} ex: FF5555CC
|
||||
*/
|
||||
toHexa: function() {
|
||||
var source = this.getSource(), a;
|
||||
|
||||
a = source[3] * 255;
|
||||
a = a.toString(16);
|
||||
a = (a.length === 1) ? ('0' + a) : a;
|
||||
|
||||
return this.toHex() + a.toUpperCase();
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets value of alpha channel for this color
|
||||
* @return {Number} 0-1
|
||||
|
|
|
|||
|
|
@ -84,12 +84,22 @@
|
|||
equal(oColor.toHex(), '000000');
|
||||
});
|
||||
|
||||
test('toHexa', function() {
|
||||
var oColor = new fabric.Color('ffffffff');
|
||||
ok(typeof oColor.toHexa == 'function');
|
||||
equal(oColor.toHexa(), 'FFFFFFFF');
|
||||
oColor.setSource([255,255,255,0.8]);
|
||||
equal(oColor.toHexa(), 'FFFFFFCC');
|
||||
});
|
||||
|
||||
test('getAlpha', function() {
|
||||
var oColor = new fabric.Color('ffffff');
|
||||
ok(typeof oColor.getAlpha == 'function');
|
||||
equal(oColor.getAlpha(), 1);
|
||||
oColor.setSource([10,20,30, 0.456]);
|
||||
equal(oColor.getAlpha(), 0.456);
|
||||
oColor = new fabric.Color('ffffffcc');
|
||||
equal(oColor.getAlpha(), 0.8);
|
||||
});
|
||||
|
||||
test('setAlpha', function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue