Font Awesome direct support

This commit is contained in:
Robert Bendun 2021-04-19 15:08:57 +02:00
parent c26931c8df
commit 36513e5869
2 changed files with 24 additions and 14 deletions

View File

@ -5,13 +5,13 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Styles --> <!-- Dependencies -->
<script src="fontawesome/js/all.min.js"></script>
<link rel="preconnect" href="https://fonts.gstatic.com"> <link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
<link rel="stylesheet" href="styles.css">
<!-- <link rel="stylesheet" href="fontawesome/css/all.min.css"> -->
<!-- Styles -->
<link rel="stylesheet" href="styles.css">
<!-- Modules --> <!-- Modules -->
<script src="modules/configuration.js"></script> <script src="modules/configuration.js"></script>

View File

@ -3,27 +3,37 @@ class Product {
* Stwórz produkt o określonej nazwie i ikonie * Stwórz produkt o określonej nazwie i ikonie
* @param {string} name * @param {string} name
* @param {string} icon * @param {string} icon
* @example const product = new Product('apple', 'fa-apple') * @example const product = new Product('apple', 'fa-apple-alt')
*/ */
constructor(name, icon) { constructor(name, icon) {
this.name = name; this.name = name;
const match = /^([a-z]+)-(.*)/.exec(icon);
if (match) {
const [_, prefix, iconName] = match;
const result = FontAwesome.findIconDefinition({ prefix, iconName });
if (!result)
throw new Error('Font Awesome does NOT have this icon');
this.icon = String.fromCodePoint(parseInt(result.icon[3], 16));
} else {
this.icon = icon; this.icon = icon;
} }
}
equals(other) { equals(other) {
return this.name === other.name return this.name === other.name;
} }
static get REGISTRY() { static get REGISTRY() {
return { return {
empty: new Product('', ''), empty: new Product('', ''),
apple: new Product('apple', '\uf5d1'), apple: new Product('apple', 'fa-apple-alt'),
bacon: new Product('bacon', '\uf7e5'), bacon: new Product('bacon', 'fa-bacon'),
bone: new Product('bone', '\uf5d7'), bone: new Product('bone', 'fa-bone'),
bread: new Product('bread', '\uf7ec'), bread: new Product('bread', 'fa-bread-slice'),
candyCane: new Product('candy cane', '\uf786'), candyCane: new Product('candy cane', 'fa-candy-cane'),
carrot: new Product('carrot', '\uf787'), carrot: new Product('carrot', 'fa-carrot'),
cheese: new Product('cheese', '\uf7ef') cheese: new Product('cheese', 'fa-cheese')
}; };
} }