(function(){
var colours = {
primaryNormal: 'custom-colour__primary--default',
secondaryNormal: 'custom-colour__secondary--default',
printNormal: function() {
print(this.primaryNormal + ' ' + this.secondaryNormal + ' ');
},
sectorsAndCapabilities: [],
relatedExpertise: [],
printRelatedExpertise: function() {
if (this.relatedExpertise.length) {
print('custom-colour__primary--%' + 'globals_asset_metadata_Colour.palette.primary:' + this.relatedExpertise[0] + '^as_asset:asset_name^lowercase^replace: :-' + '%');
print(' ');
print('custom-colour__secondary--%' + 'globals_asset_metadata_Colour.palette.secondary:' + this.relatedExpertise[0] + '^as_asset:asset_name^lowercase^replace: :-' + '%');
print(' ');
} else {
this.printNormal();
}
},
printSectorsAndCapabilities: function() {
if (this.sectorsAndCapabilities.length) {
print('custom-colour__primary--%' + 'globals_asset_metadata_Colour.palette.primary:' + this.sectorsAndCapabilities[0] + '^as_asset:asset_name^lowercase^replace: :-' + '%');
print(' ');
print('custom-colour__secondary--%' + 'globals_asset_metadata_Colour.palette.secondary:' + this.sectorsAndCapabilities[0] + '^as_asset:asset_name^lowercase^replace: :-' + '%');
print(' ');
} else {
this.printNormal();
}
}
};
var isPerson = false;
var isInsight = false;
var isEvent = false;
if (isPerson) {
colours.printSectorsAndCapabilities();
}
if (isInsight || isEvent) {
colours.printRelatedExpertise();
}
if (!(isPerson || isInsight || isEvent)) {
colours.printNormal();
}
// Text Colours
var WHITE = "custom-colour__contrasting--white";
var BLACK = "custom-colour__contrasting--black";
var THRESHOLD = 0.3;
// Convert Hex Colours to RGB
var getRGB = function(hex) {
var color = hex.replace("#", "").slice(0, 6);
// Convert Hex to RGB
return color.match(/.{1,2}/g).map(function(value) {
return parseInt(value, 16);
});
};
// Determine ideal contrasting text colour given a background colour
var getContrastingColor = function(hex) {
var rgb = getRGB(hex);
// Calculate adjusted values for each RGB value, to be used to determine the
// "relative luminance" of each colour:
// https://en.wikipedia.org/wiki/Relative_luminance
var adjusted = rgb.map(function(value) {
value = value / 255;
if (value < 0.03928) {
value = value / 12.92;
}
else {
value = (value + 0.055) / 1.055;
value = Math.pow(value, 2.4);
}
return value;
});
var luminance = adjusted[0] * 0.2126 + adjusted[1] * 0.7152 + adjusted[2] * 0.0722;
if (luminance > THRESHOLD) {
return BLACK;
}
return WHITE;
};
var primaryColourHex;
if (isPerson) {
primaryColourHex = ""; // print hex of the Sector associated with person
}
if (isInsight || isEvent) {
primaryColourHex = ""; // print hex of the Sector associated with news/event
}
if (!primaryColourHex) {
primaryColourHex = "";
}
// DEFAULT COLOUR
if (!primaryColourHex) {
primaryColourHex = "412d5e";
}
if (primaryColourHex) {
print(getContrastingColor(primaryColourHex));
}
})();
%frontend_asset_assetid^replace:{globals_site_assetid}|{globals_site_index_id}:H^eq:H:home:inside% " data-root-url="%globals_site_url%">