mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-25 08:26:52 +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:
parent
5d1cf251b9
commit
6b39d6aa43
@ -31,7 +31,12 @@ function SimpleEngine(options) {
|
||||
if(this.widget.editTag === "textarea") {
|
||||
this.domNode.appendChild(this.widget.document.createTextNode(this.value));
|
||||
} else {
|
||||
this.domNode.value = this.value;
|
||||
if(this.widget.editType === "color") {
|
||||
// The <input type="color"> element requires a six digit hex value
|
||||
this.domNode.value = $tw.utils.convertColorToCSSRGBString(this.value);
|
||||
} else {
|
||||
this.domNode.value = this.value;
|
||||
}
|
||||
}
|
||||
// Set the attributes
|
||||
if(this.widget.editType && this.widget.editTag !== "textarea") {
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user