Fixed bügs, separated special static function for generating binary.
This commit is contained in:
parent
0a5cf1419b
commit
73b5844991
@ -69,8 +69,16 @@ template.innerHTML = `
|
|||||||
|
|
||||||
class PatekLogo extends HTMLElement {
|
class PatekLogo extends HTMLElement {
|
||||||
calculateCircles() {
|
calculateCircles() {
|
||||||
const inputValue = typeof this.attributes.title !== "undefined" ? this.attributes.title.value : "Pátek";
|
const inputValue = typeof this.attributes.title !== "undefined" && this.attributes.title.value !== "" ? this.attributes.title.value : "Pátek";
|
||||||
|
|
||||||
|
const opacities = PatekLogo.calculateBinary(inputValue);
|
||||||
|
|
||||||
|
for (let i = 0; i < 7; i++) {
|
||||||
|
this.shadow.getElementById("circle" + i.toString()).style.fillOpacity = opacities[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static calculateBinary(inputValue) {
|
||||||
/* eslint no-control-regex: "off", "unicorn/no-hex-escape": off */
|
/* eslint no-control-regex: "off", "unicorn/no-hex-escape": off */
|
||||||
const normalizedInputValue = inputValue.normalize("NFD").replace(/[^\x00-\x7F]/g, "");
|
const normalizedInputValue = inputValue.normalize("NFD").replace(/[^\x00-\x7F]/g, "");
|
||||||
|
|
||||||
@ -79,15 +87,9 @@ class PatekLogo extends HTMLElement {
|
|||||||
outputChar ^= normalizedInputValue[i].charCodeAt(0);
|
outputChar ^= normalizedInputValue[i].charCodeAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const opacities = outputChar.toString(2);
|
const outputString = outputChar.toString(2);
|
||||||
|
|
||||||
this.shadow.getElementById("circle0").style.fillOpacity = opacities[0];
|
return "0".repeat(7 - outputString.length) + outputString;
|
||||||
this.shadow.getElementById("circle1").style.fillOpacity = opacities[1];
|
|
||||||
this.shadow.getElementById("circle2").style.fillOpacity = opacities[2];
|
|
||||||
this.shadow.getElementById("circle3").style.fillOpacity = opacities[3];
|
|
||||||
this.shadow.getElementById("circle4").style.fillOpacity = opacities[4];
|
|
||||||
this.shadow.getElementById("circle5").style.fillOpacity = opacities[5];
|
|
||||||
this.shadow.getElementById("circle6").style.fillOpacity = opacities[6];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
Loading…
Reference in New Issue
Block a user