Code style update.

This commit is contained in:
Greenscreener 2019-07-17 22:47:35 +02:00
parent ebb95c5f91
commit 0a5cf1419b
3 changed files with 45 additions and 39 deletions

View File

@ -3,9 +3,9 @@
Reusable custom element for the Pátek logo. Reusable custom element for the Pátek logo.
## Installation ## Installation
Include the patekLogo.js file into your HTML file. Include the patek-logo.js file into your HTML file.
```html ```html
<script src="path/to/patekLogo.js"></script> <script src="path/to/patek-logo.js"></script>
``` ```
## Usage ## Usage

View File

@ -35,6 +35,6 @@
<p><patek-logo title="Space" subtitle="Pátek" style="font-size: 50px; color: white; background-color: #24007f;"></patek-logo></p> <p><patek-logo title="Space" subtitle="Pátek" style="font-size: 50px; color: white; background-color: #24007f;"></patek-logo></p>
<br> <br>
<div style="font-size: 20px;"> Vae, germanus ausus! Fermiums observare, tanquam domesticus luna. Heu. Animalis regius advena est. Pol, a bene axona. Pes, itineris tramitem, et lixa. Hydras sunt orexiss de flavum demolitione. Cur homo <patek-logo title="cadunt?"></patek-logo> Absolutios mori, tanquam regius gallus. Zirbus, imber, et orexis. Ventuss sunt apolloniatess de emeritis lapsus. Apolloniates neuter onus est. Aususs tolerare! Cur visus trabem? Vae. <a href="https://example.com"> <patek-logo title="Example!"></patek-logo></a> Exemplar, cacula, et scutum. Byssus trabems, tanquam velox danista. Calceuss assimilant!</div> <div style="font-size: 20px;"> Vae, germanus ausus! Fermiums observare, tanquam domesticus luna. Heu. Animalis regius advena est. Pol, a bene axona. Pes, itineris tramitem, et lixa. Hydras sunt orexiss de flavum demolitione. Cur homo <patek-logo title="cadunt?"></patek-logo> Absolutios mori, tanquam regius gallus. Zirbus, imber, et orexis. Ventuss sunt apolloniatess de emeritis lapsus. Apolloniates neuter onus est. Aususs tolerare! Cur visus trabem? Vae. <a href="https://example.com"> <patek-logo title="Example!"></patek-logo></a> Exemplar, cacula, et scutum. Byssus trabems, tanquam velox danista. Calceuss assimilant!</div>
<script src="patekLogo.js"></script> <script src="patek-logo.js"></script>
</body> </body>
</html> </html>

View File

@ -71,12 +71,14 @@ 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 : "Pátek";
/* 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, "");
let outputChar = String.fromCharCode(0); let outputChar = String.fromCharCode(0);
for (let i = 0; i < normalizedInputValue.length; i++) { for (let i = 0; i < normalizedInputValue.length; i++) {
outputChar ^= normalizedInputValue[i].charCodeAt(0); outputChar ^= normalizedInputValue[i].charCodeAt(0);
} }
const opacities = outputChar.toString(2); const opacities = outputChar.toString(2);
this.shadow.getElementById("circle0").style.fillOpacity = opacities[0]; this.shadow.getElementById("circle0").style.fillOpacity = opacities[0];
@ -86,8 +88,8 @@ class PatekLogo extends HTMLElement {
this.shadow.getElementById("circle4").style.fillOpacity = opacities[4]; this.shadow.getElementById("circle4").style.fillOpacity = opacities[4];
this.shadow.getElementById("circle5").style.fillOpacity = opacities[5]; this.shadow.getElementById("circle5").style.fillOpacity = opacities[5];
this.shadow.getElementById("circle6").style.fillOpacity = opacities[6]; this.shadow.getElementById("circle6").style.fillOpacity = opacities[6];
} }
constructor() { constructor() {
super(); super();
this.shadow = this.attachShadow({mode: "open"}); this.shadow = this.attachShadow({mode: "open"});
@ -95,16 +97,20 @@ class PatekLogo extends HTMLElement {
clone.getElementById("titlePlaceholder").innerText = typeof this.attributes.title !== "undefined" ? this.attributes.title.value : "Pátek"; clone.getElementById("titlePlaceholder").innerText = typeof this.attributes.title !== "undefined" ? this.attributes.title.value : "Pátek";
clone.getElementById("titleText").innerText = typeof this.attributes.title !== "undefined" ? this.attributes.title.value : "Pátek"; clone.getElementById("titleText").innerText = typeof this.attributes.title !== "undefined" ? this.attributes.title.value : "Pátek";
clone.getElementById("subtitleText").innerText = typeof this.attributes.subtitle !== "undefined" ? this.attributes.subtitle.value : ""; clone.getElementById("subtitleText").innerText = typeof this.attributes.subtitle !== "undefined" ? this.attributes.subtitle.value : "";
this.shadow.appendChild(clone); this.shadow.append(clone);
this.calculateCircles(); this.calculateCircles();
} }
static get observedAttributes() { return ['title', 'subtitle']; }
static get observedAttributes() {
return ["title", "subtitle"];
}
attributeChangedCallback(name, oldValue, newValue) { attributeChangedCallback(name, oldValue, newValue) {
if (name === 'title') { if (name === "title") {
this.calculateCircles(); this.calculateCircles();
this.shadow.getElementById("titleText").innerText = newValue || "Pátek"; this.shadow.getElementById("titleText").innerText = newValue || "Pátek";
this.shadow.getElementById("titlePlaceholder").innerText = newValue || "Pátek"; this.shadow.getElementById("titlePlaceholder").innerText = newValue || "Pátek";
} else if (name === 'subtitle') { } else if (name === "subtitle") {
this.shadow.getElementById("subtitleText").innerText = newValue; this.shadow.getElementById("subtitleText").innerText = newValue;
} }
} }