mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-13 05:15:44 +00:00
Fix editing colours that are not in 6 digit hex format
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color#value
This commit is contained in:
@@ -41,4 +41,20 @@ exports.parseCSSColorObject = function(colourString) {
|
||||
return c;
|
||||
};
|
||||
|
||||
/*
|
||||
Convert a Color.js colour to a CSS RGB string suitable for use with the <input type="color"> element
|
||||
*/
|
||||
exports.convertColorToCSSRGBString = function(colourString) {
|
||||
var c = exports.parseCSSColorObject(colourString);
|
||||
if(c) {
|
||||
var hex = c.toString({format: "hex"});
|
||||
if(hex.length === 4) {
|
||||
hex = "#" + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
|
||||
}
|
||||
return hex;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user