V8: Support hexa in hexBgColor (#6091)
This commit is contained in:
committed by
Sebastiaan Janssen
parent
405538544f
commit
87e60ef26b
@@ -11,6 +11,11 @@ function hexBgColor() {
|
||||
restrict: "A",
|
||||
link: function (scope, element, attr, formCtrl) {
|
||||
|
||||
function setBackgroundColor(color) {
|
||||
// note: can't use element.css(), it doesn't support hexa background colors
|
||||
angular.element(element)[0].style.backgroundColor = "#" + color;
|
||||
}
|
||||
|
||||
// Only add inline hex background color if defined and not "true".
|
||||
if (attr.hexBgInline === undefined || (attr.hexBgInline !== undefined && attr.hexBgInline === "true")) {
|
||||
|
||||
@@ -26,18 +31,21 @@ function hexBgColor() {
|
||||
// Get the orig color before changing it.
|
||||
origColor = element.css("border-color");
|
||||
}
|
||||
// Validate it - test with and without the leading hash.
|
||||
if (/^([0-9a-f]{3}|[0-9a-f]{6})$/i.test(newVal)) {
|
||||
element.css("background-color", "#" + newVal);
|
||||
// Is it a regular hex value - (#)AABBCC ?
|
||||
var match = newVal.match(/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
||||
if (match && match.length) {
|
||||
setBackgroundColor(match[1]);
|
||||
return;
|
||||
}
|
||||
if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(newVal)) {
|
||||
element.css("background-color", newVal);
|
||||
// Is it a hexa value - (#)AABBCCDD ?
|
||||
match = newVal.match(/^#?([0-9a-f]{4}|[0-9a-f]{8})$/i);
|
||||
if (match && match.length) {
|
||||
setBackgroundColor(match[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
element.css("background-color", origColor);
|
||||
setBackgroundColor(origColor);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user